- Home /
How to stop a rigidbody pushing another rigidbody?
So basically i'm trying to make a fighter and stop the 2 characters from moving too close to each other. Each character has a rigidbody and a cube collider that is their "personal space", ie how close they can get to each other. I'm using my own controller script, for one because i want to and for another because i'm having some trouble with locking certain axes with the supplied ones.
The problem i have is that when a character moves into another character it pushes that character. I don't want that but i cant seem to figure out how to stop it happening. Only way i can think of is to stop any movement on that axis when this specific collision occurs but there should be some other more elegant solution. Any ideas?
If this has been asked i apologize but i can't find where :/
Did you try using Collision Layers? Edit->Project Settings->Physics.
I do use Collision Layers to make sure the box collider that is supposed to be the "personal space" of a character does not collide with anything else. But im not sure how this could help me. Can i have one layer bypass parts of the physics engine?
Answer by vbbartlett · Feb 05, 2013 at 05:23 PM
What do you want to happen when one character walks into another? This is a none trivial problem from your description. Are characters moving only in one axis or another? Or can they move diagonally at any angle?
Ideas to try when a collision happens
*determine which should not move and increase its mass.
*add a force to the character in the normal of the contact point of the collision based on the velocity of the incoming charcater
*Set one of the characters kinematic to prevent it from moving for a moment (got to turn it off again when it is over)
Well what i want is to have neither of the characters move. Basically the moving character gets handles by the physics engine and the collision is resolved by it as normal but the non-moving character should stay put. I don't want one character to be able to push another character it should be more like walking into a wall. Problem i have is that i also have to move that "wall" quite a bit. Setting one to kinematic during the collision is a interesting idea. Ill try that!
From your description, you said that one character is non-moving, I would definitely try the kinematic when the character goes to that non-moving state. Otherwise it is a hassle to figure out how to keep to characters from using and bouncing off of one another in a none realistic way physically. Especially if you want a moving to "slide" past a not moving one.
Other thoughts: change the static and dynamic friction on the physics material. If you change the Static friction to something really high, it will mean that it takes a lot of force to start the object moving, while dynamic friction is what friction is applied if the object is moving. With a really high static friction it "should" stop it from moving...
Also playing with the friction combine might help
Yea of course i didnt think that through as both can move at the same time so it all went mad. I ended up upping the friction during the collision and combining that with setting velocity to 0 on collision. Its not perfect but as the characters can push each other a bit but it works. Only way i can think of to solve it would be to bypass the physics engine completely and write my own (very limited) and i cba to do that. Thanks for the help!
Hey could you solve this issue ? can u give some advise ? im facing the same problem as well , Thanks
Sadly i did not find a solution to this problem. It worked with the objects being able to push each other ever so slightly so i moved on to more pressing issues.
Playing around with friction (and possibly density), like vbbartlett suggested, could make it less noticeable tho.
If i were to redo it today i would probably make a slightly larger hitbox that is a trigger and have that stop movement. Things got a bit wierd when the objects hitboxes were overlapping and both objects moved at the same time.
Answer by JohannaJacob · Dec 14, 2017 at 10:07 PM
I set the collider of one object to "Trigger", this fixed the issue for me.