- Home /
Walking forward
I know alot of questions about this already, but not like a I want. I want my character to move only forward and rotate left and right.
I have the script to rotate
function Update ()
{
if(Input.GetKey(KeyCode.LeftArrow))
{
transform.Rotate(0f,-5f,0f);
}
if(Input.GetKey(KeyCode.RightArrow))
{
transform.Rotate(0f,5f,0f);
}
}
Very simple script. I don't know if possible to do something like that to walk forward.
if(Input.GetKey(KeyCode.UpArrow))
{
}
Thanks for the help :)
Answer by SubatomicHero · May 28, 2013 at 12:48 PM
You need to look into using Time.deltaTime as part of your movement scripts. It helps keep movement smooth.
Moving forward would just be a case of using transform.Translate(....);
Hope this helps.
thanks works like I want, but one question.
I don't know if it is because of that but the player goes through walls.
Any solution please?
You need to add colliders/rigidbody physics components to your objects in order for them to react to each other. You can read further on this topic here: http://docs.unity3d.com/Documentation/$$anonymous$$anual/Physics.html
I tried a box collider, capsule collider and character controller.
But it stills going through walls (walls also have a box collider)
Your answer
Follow this Question
Related Questions
Make a cube rotate in right or left direction randomly 3 Answers
Rotating a cube changes its local forward? 1 Answer
left and right movement for ai 1 Answer
Check where mouse is clicked 1 Answer