- Home /
Stretchy legs and collision
Hello! I am developing a game together with my friends. If you have a 360-pad, you can play it here:
http://jollygyrojaunt.tumblr.com/play-the-game
Anyhow, the player controls a walker thing with two legs, and each analog stick controls each leg. Right now, an invisible rigid body is attached via a configurable joint to the body of the walker. This invisible rigid body has the foot attached to it with a hinge joint, allowing it to rotate. The actual leg is purely visual, and is stretched between the foot and the body.
Now, I want the leg to interact with other things in the physics engine. I tried simply attaching colliders to the leg, though that created jerky behaviour. Adding a rigidbody did not help either. I suspect that you must somehow control these colliders with velocities, not simply setting their position depending on the location of the foot.
So, my question is then: How do you construct this kind of legs in a correct way, in order for the legs to work as proper physical entities, and making them stretch nicely?
Explain what isn't working about just having a rigidbody?
Right now, I am having trouble getting any of the colliders (in the legs) to work at all. Right now, the colliders simply will not collide with anything (and they are not set to triggers), and I cannot explain that. What I am asking for then, is a "proper" way of doing, since I am not certain setting the position of a collider or rigidbody directly will make it play nice with the physics engine.
I drew a diagram to help illustrate the problem: https://dl.dropbox.com/u/845265/diagram.png
Answer by Mortoc · Jul 05, 2012 at 06:16 PM
You want to use rigidbodies (one per independently moving joint) that have isKinematic set to true. These rigidbodies then should be moved during FixedUpdate. http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.MovePosition.html
Usually this is enough for most simple collisions, but often the physics engine can't handle every situation (it is general purpose), so you may have to do sweep tests to see if you will hit something and then do some custom code to handle those situations if the general purpose solution isn't handling everything for you. http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.SweepTest.html
Thank you for answering!
I did muck about a bit with kinematic rigidbodies, but they had a tendency to mess up other physics objects. If the rigidbodies of the legs were too light, a collision to the leg would launch the entire walker across the level. A too heavy leg colliding would mess with some "see-saw" platforms, causing them to wobble way too much.
Yah, that's the challenge with physics games, you have to get the scale and mass of everything to feel solid.
A lot of times I end up "cheating" by doing rigidbody.sweeptests and writing some custom collision behavior.
Well, I fooled around with all possible permutations, and it now seems that using rigidbodies makes the legs go through anything. Seems my older findings were my imagination, or something :s. Using just colliders works, except the collision response is too forceful. So I guess I could add a kinematic rigidbody, and write my own collision response at an appropriate magnitude?
Yah, that's what I would suggest, it'll allow you to fine tune what sounds like an important part of your game.
Your answer
Follow this Question
Related Questions
How do I create a realistic chain with interlocking rings and accurate physics? 0 Answers
Changing object scale without changing collider scale 1 Answer
consecutive angularxdrive.positionspring.equals() not working 0 Answers
Bend object with physics interaction 0 Answers
Only take into account colliders' bounds on single gameobject in hierarchy 1 Answer