Hi Unity,
I am trying to make my character model rotate at a set speed for 180 degrees, while still moving forward the same direction ( because he moves forward at all times) but running into some issues. I have looked through a few scripts on here and this is what I have come up with:
(There is some code in here that also checks if you “Double Tapped” the A button instead of just pressing it.)
if(Input.GetKeyDown(KeyCode.A))
{
if(!oneTap) //check to see if this is the first time we pressed A
{
oneTap = true;
timer_for_double_tap = Time.time; //save the current time
//Add any functionality for just pressing "A" here... if you wanted
}
else
{
Debug.Log("Double Tap");
oneTap = false; // found a double tap
Transform boarderModel = GameObject.Find("SpaceBoarderModel").transform;
//Do a 180 rotation Trick!
if (!rotating)
{
rotating = true;
float curRot = 0;
float startRot = boarderModel.eulerAngles.y;
while (curRot < 180) {
curRot += rotateSpeed * Time.deltaTime;
startRot = startRot + curRot;
break;
}
startRot = Mathf.Round(startRot + 180);
rotating = false;
}
}
First I check to see if the user has tapped “A” twice, if they have, I want to start the rotation and rotate by “rotateSpeed” to 180 degrees. I use boarder model to get the transform of the actual model of my character, which is housed inside an empty gameObject named something else. The idea behind this was that the parent gameobject would continue to move forward while the child that I reference here will do the 180.
I hope that makes sense.
There is no errors, but my character does not receive any updates to their transform and of course does not rotate. Any ideas what I might have done wrong?