- Home /
Rigidbody "hopping" when crossing objects.
I cannot figure out what the cause of this is. I really hope somebody can shed some light on the cause.
I have a rigidbody with a simple sphere collider on it. My level is made up of static collidable tiles (all of equal size). When the rigidbody collides with these tiles, certain tiles apply a forward force to it with the following script:
void OnTriggerStay(Collider TheCollider)
{
TheCollider.rigidbody.AddForce(new Vector3(forceMagnitude, 0.0f, 0.0f), ForceMode.Force);
}
Now for some reason when the rigidbody crosses from one tile (the one applying the force) to another (a plain static collidable) it does a little hop as if it's hit a little step or something. I'm sure that my tiles line up perfectly square and that they are airtight where they touch each other.
Any advice would be greatly appreciated. Thanks in advance.
Answer by KeithK · Apr 03, 2011 at 01:29 PM
Eureka!
For anyone else having this problem. There is a setting in Edit->Project Settings->Physics called "Min Penetration For Penalty", this basically sets how much an object can penetrate another before being pushed apart.
My player sphere was penetrating my map tiles a little too much, and when it hit the next tile, it was like hitting a step up. This sorted it out like a charm.
Answer by Bunny83 · Apr 02, 2011 at 09:02 AM
Does your tile have a seperate trigger collider on top, or do you just mark the collider as trigger?
Colliders that are marked as trigger don'e "collide" and don't give physics feedback. Trigger can passed through, they just "trigger" something. How big are your tiles in relation to your player sphere? If you move quite fast you will just fall into the tile and then hit the edge of the next tile which pushes you up again.
Can't think of anything else...
Thanks for the quick reply. I tried commenting earlier but had a power failure while I was typing it -_-.
$$anonymous$$y tiles have a separate trigger collider added as a child.
The size of the tiles is 1 unit in all dimensions, and the player sphere is 10 times small, so 0.1. I think you're right that it is falling through and hitting the next tile's edge.
Could the physics engine not be enjoying the size of my player sphere?
That means your tiles are Unitys' default cubes? ;) If you use Boxcolliders for your tiles everything should be ok. Even a PlaneCollider should work. $$anonymous$$ake sure the collider is not marked as trigger. You can or should check this at runtime. When you enter playmode you can switch to the sceneview and select your tiles to check that there's a collider (maybe it got removed by a script?) and it does collide. You can even add a test-sphere with rigidbody right above the tile to see whether it falls through or not.
Haha. Yep, you got me, it's the default cube. They do each have a BoxCollider, which is definitely there at runtime. They are positioned right next to each other and the hop only happens at the touching sides of the cubes, it's also dependent on the velocity of the sphere at that time, some cubes it crosses over to fine. I am completely stumped as to what the cause is.
Your answer
Follow this Question
Related Questions
Ball physics help 2 Answers
Recieving a nullpointerexception while following the Unity Instantiation tutorial 1 Answer
Multiple rigidbodies stick together but still reacting to collisions from other entities? 0 Answers
Child Gameobjects are not fixed to the parent when using physics 0 Answers
calculate time to reach a target of rolling rigidbody sphere 0 Answers