The rigidbody object moves with this script:

void Update() { if (Input.GetKeyDown(KeyCode.Space)) //если нажат пробел rb.velocity = new Vector3(1, 0, 0); 

I need when: if (Input.GetKeyUp(KeyCode.Space)); change direction, speed.

I try this: rb.velocity = new Vector3(5,-1 0, 0); - the object accepts this command in the first case.

Tried through rb.useGravity = false/true , the object does not move at all. how to do it?

  • Please format the text of the question. Badly read - tutankhamun
  • In terms of speed? Slower, faster? - Artik Slayer
  • faster. This bird soars, it is necessary to dive - Georgich

1 answer 1

gameObject.transform.forward is a player direction vector. If you do this - rigidbody.velocity += transform.forward * speed; then the player will move only forward towards himself (Local - Local).

Also present: Vector3.forward not to be confused with transform.forward , the first is global.