mirror of
https://github.com/Steffo99/mission-failed.git
synced 2024-12-04 22:04:17 +00:00
updated RotateTowardsMouse. You might want to try out with and without using slerp (useSlerp boolean) and by using directly the Input.mousePosition as the lookDirection
This commit is contained in:
parent
11f6d4ae50
commit
1315015b94
1 changed files with 38 additions and 7 deletions
|
@ -2,14 +2,45 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RotateTowardsMouse : MonoBehaviour {
|
||||
//Circa qualcosa così
|
||||
public class RotateTowardsMouse : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Velocità a cui far ruotare il braccio.
|
||||
/// </summary>
|
||||
public int speed = 1;
|
||||
|
||||
void Update() {
|
||||
/// <summary>
|
||||
/// Per testing.
|
||||
/// Determina se bisogna utilizzare
|
||||
/// Quaternion.Slerp() o Quaternion.LookDirection().
|
||||
/// </summary>
|
||||
public bool useSlerp = false;
|
||||
|
||||
void Update()
|
||||
{
|
||||
//Trova la direzione tra il transform e il braccio
|
||||
Vector2 screenPosition = Camera.main.WorldToScreenPoint(transform.position);
|
||||
Vector2 direction = (Vector2)Input.mousePosition - screenPosition;
|
||||
//Cambia la rotazione dell'oggetto
|
||||
transform.rotation = Quaternion.identity;
|
||||
Vector2 screenPosition =
|
||||
Camera.main.WorldToScreenPoint(transform.position);
|
||||
|
||||
Vector2 direction =
|
||||
(Input.mousePosition - screenPosition) as Vector2;
|
||||
|
||||
Vector3 lookDirection =
|
||||
new Vector3(direction.x, direction.y);
|
||||
|
||||
/*
|
||||
* In alternativa provare direttamente con
|
||||
* lookDirection = Input.mousePosition;
|
||||
*/
|
||||
if (useSlerp)
|
||||
{
|
||||
Quaternion.Slerp (
|
||||
transform.rotation, // Rotazione iniziale
|
||||
Quaternion.LookRotation (lookDirection), // Rotazione finale
|
||||
speed * Time.deltaTime); // Velocità dell'interpolazione
|
||||
}
|
||||
|
||||
else // Questo dovrebbe bastare
|
||||
Quaternion.LookRotation (lookDirection);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue