• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Mrop · Jul 05, 2012 at 11:39 AM · physicscolliderscalingjoints

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?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Jul 05, 2012 at 11:39 AM 0
Share

Explain what isn't working about just having a rigidbody?

avatar image Mrop · Jul 05, 2012 at 06:04 PM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mrop · Jul 09, 2012 at 05:29 PM 0
Share

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.

avatar image Mortoc · Jul 09, 2012 at 05:49 PM 0
Share

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.

avatar image Mrop · Jul 11, 2012 at 06:05 PM 0
Share

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?

avatar image Mortoc · Jul 11, 2012 at 06:13 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing object scale without changing collider scale 1 Answer

Player keeps bouncing off the walls 2 Answers

Random Performance Spikes due to Physics.Processing in a static scene. 1 Answer

How to recheck collision? 1 Answer

Physic based golf game - ball bouncing off the connection of colliders on flat surface 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges