- Home /
2.5D Rotate to face Movement, How to make it stay after rotating
I have a script that turns my character left and right when i move in those directions, but how do i get the character to stay facing left or right after releasing the buttons?
void FixedUpdate()
{
float translate = Input.GetAxis("P1_Horizontal");
transform.forward = new Vector3(translate, 0, 0);
}
Answer by aWolfKing · Mar 06, 2016 at 11:35 AM
@theendbeginz i would check if Input.GetAxis("P1_Horizontal") is not 0, becouse if is is 0 then you will rotate to Vector3(0,0,0). if you check if it is not 0 then it wont rotate to Vector3(0,0,0) and stay on it's current rotation if you are not pressing any buttons. (not 100% sure but i think this will fix your problem)
void FixedUpdate() { float translate = Input.GetAxis("P1_Horizontal"); if(translate != 0f) { transform.forward = new Vector3(translate, 0, 0); } }
Thank you so much, this is exactly what I was looking for.
Answer by firewarrior2112 · Mar 04, 2016 at 08:53 AM
Perhaps this is what you are looking for?
if(Input.GetButtonDown("Fire1"))
{
transform.forward = new Vector3(translate, 0, 0);
}
This would check to see if the button (mouse 1 in my example) is down every update.
also, you should declare variables (float translate) below the header of the class, not in every update call.