- Home /
On Collision 2D object continuosly bounce/shake
So I basically have two gameobject with a boxcollider2D attached to it, one is a static wall without rigidbody and the other is let's say the player that I scripted to move using transform.position.
Apparently the object goes inside the wall's boxcollider and return to the previous position generating thus that orrible shake i'm trying to fix.
A possible solution would be using ray/linecast and would be fine to solve it that way but is there any other workaround for this problem ? I read that providing forces to the player instead of moving it with transform would be better and may fix this, but how ? What's the difference ?
Answer by jonSG · Apr 16, 2014 at 01:11 PM
The difference at a high level is the "force" / "physics" method applies a "push" that shoves your object. Think "Angry Birds" or a game of shuffleboard or darts. When you update transform.position it is more like teleporting the object rather than pushing it.
The bounce you see might be the collider and your teleportation fighting it out to find a position for your object if every frame you are attempting to teleport inside one.
It can be a challenge to convert teleportation based movement into force based movement and have something that "feels right".
One thing you can try that is easier than application of force and is much closer to updating your position is to set the velocity vector on your object rather than the position.
thanks for the answer, do you know valuable examples/documentation on how to apply vectorial velocity on 2d/3d objects to update the position?
If you check out the "character controller tutorial", I think the motion is done via setting velocity:
Quick fix : I used the rigidbody2d.velocity property and i'm setting it via a vector3 vector. No bounciness but I need to do a double check in update() (onkeydown & onkeyup ins$$anonymous$$d of just Getkey) is this what you were referring to vectorial movement ?
Ya, glad it helped,
If you wanted to, you could probably still use getkey if you multiply the velocity by Time.DeltaTime or set the velocity in FixedUpdate() rather than Update()
Answer by WilldD · Oct 09, 2020 at 12:41 PM
In my case, one of the two colliders had a high bounciness material. Removing the material fixed the issue for me.