针对一个物的方向旋转

public float speed=90;

[SerializeField]

Transform targot;

Quaternion destrot = Quaternion.identity;

float rotX;

float rotY;

float PivotDistance = 10;

float rotSpeed = 10;


void Update()

{

float Horz = CrossPlatformInputManager.GetAxis("Horizontal");

float vert = CrossPlatformInputManager.GetAxis("Vertical");

rotX += Horz * Time.deltaTime * rotSpeed;

rotY += vert * Time.deltaTime * rotSpeed;

Quaternion yrot = Quaternion.Euler(0, rotY, 0);

destrot = yrot * Quaternion.Euler(rotX, 0, 0);

transform.rotation = destrot;

transform.position = targot.position + transform.rotation * Vector3.forward * -PivotDistance;

}

你可能感兴趣的:(针对一个物的方向旋转)