Trouble with position.y of mesh (shakes continuously)

Hello guys,

My problem is that I am trying to change the y-position of my mesh when it collides with another mesh. So far I’ve been able to get it to increment so that it juxtaposes and then when it’s no longer in contact, it returns to its original position. The problem is that when I move it, it “shakes” continuously because it tries to move back continuously and I would like that to happen only when it is not in contact with another mesh.

Here is my playground so it will be more understandable : https://playground.babylonjs.com/#7CBW04#1687

Thank you in advance and sorry for my english ^^’

1 Like

Your english is perfect !!! let me add @RaananW and @Cedric to the thread :slight_smile:

1 Like

Thank you! You have my full attention ! ^^

the shaking problem happens because you either increase or decrease Y each frame. One frame, there is a collision with a ground, Y is increase. next frame, no collision and Y is decreased, etc … and you get the mesh shaking each frame when mouse is moved.
To fix it, I guess it’s possible to do a raycast to the ground. Or use a physics engine.

1 Like

Yes, that’s why I was thinking of adding a condition to my loop asking it to recalculate its position only when the mesh has been in contact with another mesh the previous frame and no other time but I don’t know how to formulate it.

But I’m gonna check this raycast thing, I dont know yet what it is but I will search.

Thank you!

1 Like