|
I have a GameObject hierarchy setup like this: Now the physics part of the player is not a character controller, but a rigid body (because I require more than just the y axis of rotation). When I press 'w', the game should add a force to the rigidbody so that it moves towards wherever its forward is (it is a relative force of Vector3.forward). The Physics is rotated along its y axis using mouse input, and the camera is rotated along its x axis also using mouse input. My problem is, when the camera is looking down, the added force is very low, and when the camera looks up, the added force is very high. When I detach the camera from the hierarchy the force application behaves fine, so why does the camera being a child affect the parent rigidbody? If I need to give any clarification, let me know - it was kind of hard to explain. Here is my physics code:
(comments are locked)
|
|
I'd guess we'd need to see the code for the physics - but as a guess without it - your 1stPersonGun has a collider attached to it. In which case the collider acts as a part of the parent rigidbody's physical structure and will alter the forces applied to it significantly. This would explain why different angles affected the force differently as the gun is changing its position as the camera moves and hence altering the shape of the object onto which you are applying physics. Do one of these:
EDIT The final solution to this was to make sure that physics code refers to the transform.forward of the actual item with the rigidbody.
My physics code is now in the main question.
Jul 13 '12 at 03:03 PM
Zantom07
So could you:
Jul 13 '12 at 03:08 PM
whydoidoit
Ok I have added the physics code and hierarchy picture to the bottom of the question.
Jul 13 '12 at 03:18 PM
Zantom07
Just a couple of things on that code (which isn't the problem by the look of things!):
Under Musket - you are absolutely sure that there is nothing with a collider (nor does the camera have one?). Because that would totally explain it... Your physics works well
Jul 13 '12 at 03:26 PM
whydoidoit
Ok thanks for the 2 tips. I just tried moving the camera out the hierarchy, and rotating it along the x axis still somehow affects where this 'Player.forward' is. The only thing that could possibly be affecting it is the fact that the physics code is on the camera and not on the player. I will try a few more things out - if you have any suggestions please tell me :)
Jul 13 '12 at 03:37 PM
Zantom07
(comments are locked)
|

Does 1stPersonGun have a rigidbody associated with it?
Are you getting your relative forward vector based on the Camera's space at all?
@FishSpeaker
No, it doesn't
And I don't think so. I am getting the player physics rigidbody, then doing AddRelativeForce(Vector3.forward, ForceMode.Acceleration);