- Home /
AddForce relative to camera rotation
Hi Unity,
I'm not a complete newb, but I'm really stumped by this one. I have a game that uses a 3rd person controller and smooth follow camera script. The net effect, it that I have a world my character plays in that is full 3d, but the camera stays in sync with the character on his X & Y axis(NON ORBITING). In addition to this, I have a 2nd player on the screen who acts as a rover (rolling ball) who operates independently from the main character. My 2nd player is typically controlled by the right analog joystick of a PS3 or XBOX Controller. The control is driven by calling rigidbody.AddForce() on the ball itself. My problem arises when my levels do not have strict X & Y level design applied to them. It seems that rigidbody.AddForce() is relative to world coordinates and not current input direction.
Ideally, I would like to call AddRelativeForce based off of the the current camera rotation, but I'm really struggling with how to do that.
Anyone else ever have a situation like this?
Thanks,
John
I cannot visualize your setup. You say the camera follows on the X & Y (NON ORBITING), which implies there is no camera rotation, but you write of using the camera's rotation for adding your force. I think you need a diagram, or a short video, or something to demonstrate the setup. The solution is probably easy once the setup is clear.
Answer by iwaldrop · Jan 08, 2014 at 05:04 AM
You didn't post any code, and I agree with robertbu that it is difficult to tell exactly what you mean, but I think I may understand you, and it seems pretty simple. Use Camera.main.transform.left or its inverse instead of Vector3.left.