All other answers related to AddForce relative to camera position only explain how to add force forward and backward. I’ve got that part down, but I need to be able to move left and right.
Vector3 pushDir = GameObject.Find("cameraMan").transform.position - transform.position;
if (Input.GetKey("up") || Input.GetKey("down"))
{
rb.AddForce(pushDir.normalized * Input.GetAxis("Vertical") * (-10));
}
This code works fine, I already have a script that rotates the camera and this always moves you forwards/backwards from its perspective. But when I try to write this for left/right movement:
if (Input.GetKey("right") || Input.GetKey("left"))
{
rb.AddForce(sideDir.normalized * Input.GetAxis("Horizontal") * (-10));
}
It still only moves forwards and backwards. I’ve tried pushDir.right, pushDir.normalized.right, I even tried making a perpendicular child for the camera, to see if moving back and forth relative to that object would move me left and right; no dice.
Side note: this is a game about moving around a spinning ball, AddForce is what I’d like to use for that movement.
Any help is much appreciated!