I'm trying to write a script that defines the motion of a player-type character in a 3D game by calling rigidbody.addForce, but the console is telling me that there is no Rigidbody2D attached. I'm aware of this, as there's a Rigidbody attached, not a Rigidbody2D, on purpose. I want this to be a 3D game.
void FixedUpdate () {
if (Input.GetKey (KeyCode.W)) { //forward
rigidbody.AddForce(0, 0, 2);
}
if (Input.GetKey (KeyCode.S)) { //back
rigidbody.AddForce(0, 0, -2);
}
if (Input.GetKey (KeyCode.A)) { //left
rigidbody.AddForce(-2, 0, 0);
}
if (Input.GetKey (KeyCode.D)) { //right
rigidbody.AddForce(2, 0, 0);
}
}
↧