I want to have a very basic game in which a sphere rolls around with the camera following it. I have it set up so when W is pressed it uses rb.addforce (rb being my rigidbody). When D is pressed it rotates the sphere using the Space.World. If I use rb.addForce it always pushed the sphere forward on the world axis regardless of if I rotate the sphere. If I use rb.addRelativeForce it will push the sphere in the direction the sphere is facing but because the sphere rolls forward my script ends up pushing the sphere down. Is there a way to use some axes of the local space and some of the world space for rotation?
Here is my Code:
public float speed;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (0.0f, 0.0f, moveVertical);
rb.AddRelativeForce (movement * speed);
if (Input.GetKey ("a")) {
transform.Rotate (0, -5, 0);
}
if (Input.GetKey ("d")) {
transform.Rotate (0, 5, 0);
}
}