dustxx
1
When I try and move a rigidbody with the MovePosition(Vector3) function, it moves in the direction of that actual vector3. I want it to move by that vector3 in the direction the rigidbody is already facing. here’s my current code. What would I use to do this correctly?
void FixedUpdate ()
{
//Take input for movement
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
movement *= speed;
//Move
rigidbody.MovePosition (rigidbody.position + movement * Time.deltaTime);
//Take input for rotation
Vector3 rotation = new Vector3( 0f, Input.GetAxis("Turn"), 0f);
rotation *= rotateSpeed;
//Rotate
rigidbody.MoveRotation (transform.rotation * Quaternion.Euler(rotation));
}
dustxx
2
ah, yeah. I realized that a bit after posting this question and I rewrote it to move based on the forward. Like this:
//Take input for rotation
Vector3 rotation = new Vector3( 0f, Input.GetAxis("Turn"), 0f);
rotation *= rotateSpeed;
//Rotate
rigidbody.MoveRotation (transform.rotation * Quaternion.Euler(rotation));
//Take input for vertical movement
float moveVert = Input.GetAxis ("Vertical");
moveVert *= speed;
//Move vertically
rigidbody.MovePosition (rigidbody.position + (transform.forward * moveVert) * Time.deltaTime);
//Take input for horizontal movement
float moveHorz = Input.GetAxis ("Horizontal");
moveHorz *= speed;
//Move horizontally
rigidbody.MovePosition (rigidbody.position + (transform.right * moveHorz) * Time.deltaTime);
Sorry if the orighinal question was confusing