- Home /
Quaternion Clamp on my code.,Quaternion clamp X
I need help blocking the x-rotation of the rotationTransform, but I still haven't been able to find the solution. Thank you! I am new at this.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class InputManager : MonoBehaviour {
public Transform rotationTransform;
public float normalSpeed = 1f;
public float fastSpeed = 3f;
public float movementTime = 10f;
public float rotationSpeed = 1f;
//////
private Quaternion newRotation;
private Vector3 startPosition;
private Vector3 currentPosition;
private Quaternion yaw;
private Quaternion pitch;
private float angleClamped;
void Start(){
newRotation = rotationTransform.rotation;
}
void LateUpdate(){
HandleMouseInput();
}
/*void Update();*/
void HandleMouseInput(){
//Giro
if(Input.GetMouseButtonDown(2)){
startPosition = Input.mousePosition;
}
if(Input.GetMouseButton(2)){
currentPosition = Input.mousePosition;
Vector3 difference = startPosition - currentPosition;
startPosition = currentPosition;
yaw = Quaternion.AngleAxis(-difference.x / 5f, Vector3.up) * newRotation;
pitch = Quaternion.AngleAxis(-difference.y / 5f, Vector3.right);
newRotation = yaw * pitch;
}
}
//Giro
rotationTransform.rotation = Quaternion.Lerp(rotationTransform.rotation, newRotation, Time.deltaTime * movementTime);
}
}
Comment