My script is almost 200 lines long, so I'll just post the rotation function.
Essentially what happens is that after the ship has moved a few units, it'll stop rotating properly and basically get locked to a certain rotation. At first I thought the RotationSpeed variable somehow got decreased to a really small value, but that's not what happens. I feel like I'm overlooking something here. Making my avatar slow down and then try to rotate it doesn't work, so I doubt it has something to do with it moving at a certain speed. I feel like I'm overlooking something obvious here.
You're going to want to look within the else statement, that's the code I cannot get to work for the life of me.
void Rotate()
{
ManagerScript Manager = GameObject.Find ("TargetingManager").GetComponent();
if (HasTarget && Manager.CurrentTarget != null)
{
newRotation = Quaternion.LookRotation(new Vector3(Manager.CurrentTarget.transform.position.x - transform.position.x, 0,
Manager.CurrentTarget.transform.position.z - transform.position.z), Vector3.up); //Sets rotational value to be that of the target
transform.LookAt(Manager.CurrentTarget.transform);
}
else
{
if (Input.touchCount > 0)
{
newRotation = Quaternion.LookRotation(new Vector3(WorldPointVector.x, 0, WorldPointVector.z)); //Sets rotational value to be that of the input touch
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, RotationSpeed * Time.deltaTime);
}
}
}
Here's the WorldPointVector variable
WorldPointVector = Camera.main.ScreenToWorldPoint(new Vector3(lastTouch.position.x, lastTouch.position.y, 10));
↧