Hello, I’ve recently started using Unity, and have been using C# as my scripting language of preference. Just as the question says, I’m trying to roll a rigid body sphere in relation to the Y axis of the camera but not the X axis. I have searched both questions and the forums but have been unable to figure this out. The code I’m currently using works well going forward and backward, but unless the camera’s X rotation is exactly 0.0f, it causes the sphere to roll offset by the X rotation of the camera. Here is a listing of my current code:
void FixedUpdate () {
if (Input.GetKey ("w"))
rigidbody.AddTorque(Camera.main.transform.right * speed * Time.deltaTime);
if (Input.GetKey ("a"))
rigidbody.AddTorque(Camera.main.transform.forward * speed * Time.deltaTime);
if (Input.GetKey ("s"))
rigidbody.AddTorque(Camera.main.transform.right * -speed * Time.deltaTime);
if (Input.GetKey ("d"))
rigidbody.AddTorque(Camera.main.transform.forward * -speed * Time.deltaTime);
}
I’m sure there’s a fairly easy fix for this, but I’ve been bashing my head on it for a couple hours so I figured I would ask. Thank you in advance!