Trying to write a basic script to attach to the player on Unity 3D, I want them to move forward automatically. I'm guessing that will be part of the Update function and using transform, but that's about as far as I get.

I'm assuming it's a Transform.translate function too, but not sure what parameters to use to move forward 1 m/s automatically (for example). Also, how do I block W and S keys moving forwards and backwards, and instead use the for up and down? (My character is 'floating' and I'm looking to incorporate space harrier style controls)

Thank you!

share|improve this question

2 Answers

up vote 1 down vote accepted

The first sample code is what you want. http://unity3d.com/support/documentation/ScriptReference/Transform.Translate.html

function Update() 
{
    transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * Time.deltaTime);
}

Vector3.forward is the same as (0,0,1), and transform.Translate() is local translate, so Translate(0,0,1) is always moving forward. Time.deltaTime let speed equal to 1 m/s.

And you can change the default key in "Input Manager" http://unity3d.com/support/documentation/Components/class-InputManager.html

share|improve this answer
Ah, great, thank you :) – David Archer Nov 7 '11 at 12:32

You should be using a Character Controller and use either SimpleMove or Move.

share|improve this answer
Are there any tutorials, videos etc. that covers this is a little more detail? Just looking at those links has only succeeded in confusing me a little more. – David Archer Nov 7 '11 at 12:21

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.