- Home /
Changing to use relative Axis
I have a simple marble rolling game right now. The marble will move and everything, but only along the x and z axis relative to the world.
void FixedUpdate()
{
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 have a camera mouse orbit applied to my main camera so the player can orbit around the ball. However, even if i move the camera, the ball doesn't change. It will still move along the world axis. If i have the camera facing one way and I make the ball move forward, instead of it moving in the direction I'm looking it moves forward in the world. How can i change this so the ball moves relative to the camera? thanks in advance.
Answer by robertbu · May 14, 2014 at 04:20 AM
Between lines 6 and 8, add:
movement = Camera.main.transform.TransformDirection(movement);
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
C# HUD axis button display 0 Answers
Z axis change 2 Answers
How to get Unet to recognise rotation? 2 Answers