Before updating to Windows 10 you may need to return your Pro license. More information here

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?



more ▼

asked Jan 08, 2014 at 04:50 AM

avatar image

64 4 898 11

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.

Jan 08, 2014 at 04:53 AM robertbu
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jan 08, 2014 at 05:04 AM

avatar image

7.6k 3 8 24

That worked for me, Thanks!

Jan 08, 2014 at 06:16 AM JohnRossitter
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jan 08, 2014 at 04:50 AM

Seen: 599 times

Last Updated: Jan 08, 2014 at 06:16 AM