How do I make AddForce apply force relative to the rotation of another object?
I currently have a camera inside a sphere. The following code is used to move the sphere:
void FixedUpdate () {
//Define input and apply force
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3 (moveHorizontal,0.0f,moveVertical);
rigidbody.AddForce(movement * speed * Time.deltaTime);
}
I need the force that is applied to the sphere to take into account the rotation of the camera so that moving forwards is relative to the camera rather than the world.
Any help is much appreciated!
Comment