- Home /
Add force in the camera direction??
I want to addforce in the direction that the camera is facing. The only problem is that the camera is slightly pointing down. So if I go backwards, the ball starts the float a little. I am currently using:
var moveRelativeVerticalRaw : Vector3 = camera.main.transform.forward * Input.GetAxis("Vertical");
rigidbody.AddForce(moveRelativeVerticalRaw / 2, ForceMode.Impulse);
but again this adds force in the camera's tilted direction :(
So basically, I guess how would I make it so that the force applied is parallel to the ground?? or, is there any other way of doing this?
Comment
Best Answer
Answer by robertbu · Jan 22, 2014 at 07:11 AM
Simply zero out the 'y' from the camera's transform.forward:
var camForward = camera.main.transform.forward;
cam.y = 0.0;
var moveRelativeVerticalRaw : Vector3 = camForward * Input.GetAxis("Vertical");
rigidbody.AddForce(moveRelativeVerticalRaw / 2, ForceMode.Impulse);