Hi all, I am creating a 2D top-down rescue game. Where the player has to go around rescuing civilians using arrow keys.
Both the player and the civilians share the same script. Both have rigidbodies attached to them. Basically I check for the 'player' tag when using script on the player.
Anw, currently I'm doing this to move the rigidbodies:
But if the civilian hits anything, it'll spin.
I tried using Is Kinematic or
Thanks in advance for your help.
asked Dec 17 '10 at 02:26 AM
I take it you don't want any rotations at all?
You can check the checkbox "Freeze Rotation" on your rigid bodies through the editor. This will stop rotation all together. Alternatively you can set it through script:
answered Dec 17 '10 at 02:34 AM
This is going to sound strange, but it works. Add a configurable Joint to the civilian, and don't connect the joint to anything, but do add the following settings to the joint to stop ALL rotation:
civilian.GetComponent(ConfigurableJoint).angularXMotion = ConfigurableJointMotion.Locked; civilian.GetComponent(ConfigurableJoint).angularYMotion = ConfigurableJointMotion.Locked; civilian.GetComponent(ConfigurableJoint).angularZMotion = ConfigurableJointMotion.Locked;
If you're top down, you may want to free up one axis for rotation so you can have the civilian rotate to face the direction he's heading, just set the desired X,Y or Z to .Free; depending on which way your cameras making the desired axis.
This is strange, I think, because configurable joint is useful when not connected to anything.
You can also use the configurable joint to lock out Z-movement from your camera view of the object if you're making a 2D game and this becomes a problem when they get smacked by physics events. Assuming Z is depth from camera view: GetComponent(ConfigurableJoint).zMotion = ConfigurableJointMotion.Locked;
isKinematic stops all responses to physics events, allowing you only control via direct changes to the objects transform, however other objects when hitting your isKinematic object respond to it physically.
answered Dec 17 '10 at 03:39 PM