- Home /
This question was
closed Oct 18, 2012 at 01:07 AM by
Coreyf716 for the following reason:
The question is answered, right answer was accepted
Question by
Coreyf716 · Sep 08, 2012 at 11:06 PM ·
javascriptrigidbodytransformcontrollergravity
Player Falls Over
I'm using a simple script to make the player move.
function Start () {
}
var MoveAmount = 0.15;
function Update () {
if (Input.GetKey(KeyCode.W)) {
transform.Translate (Vector3.forward * MoveAmount);
}
if (Input.GetKey(KeyCode.A)) {
transform.Translate (Vector3.left * MoveAmount);
}
if (Input.GetKey(KeyCode.S)) {
transform.Translate (Vector3.back * MoveAmount);
}
if (Input.GetKey(KeyCode.D)) {
transform.Translate (Vector3.right * MoveAmount);
}
}
I wanted to apply gravity to the player, so I added a rigidbody. The player is a capsule, so when it was translated, it literally just fell over. How can I fix this?
Comment
Best Answer
Answer by Piflik · Sep 08, 2012 at 11:16 PM
function Awake() {
rigidbody.freezeRotation = true;
}
rigidbody.freezeRotation also works as a function Start. Is it a good idea to use it this way rather than function Awake?
Doesn't matter. Awake is called before Start (all awake functions in the scene are called, before the first start function), so if functions depend on other variables, it would be advisable to keep that in $$anonymous$$d, but this doesn't depend on anything.