Rigidbody2D, Velocity in y direction does not become 0 after collsion with ground

Godot Version

Godot v4.2.1


The main character in my game is a rigidbody, and I am facing problem displaying particles when ball bounces off of something. I want particles to emit when the ball bounces from walls or floor, but I do not want them when the object is stationary. The Problem is that the velocity in y direction is not becoming 0 (probably because how I wrote logic for bouncing)

I’m a beginner so im not sure what to do

What I tried

  • clamping velocity to 0 when it is between a certain threshold, but it does not seem to work well with bounce.
  • checking velocity when display particles, if linear_velocity.y < -60 or velocity.x != 0, this does not work either because velocity in x direction is not becoming 0.
  • tried changing damp coefficients, didn’t work.

Also I would like to know why does the velocity change, when I drag with mouse (watch linked video for context)

link to repo and screen capture

I’m looking at the calculations, but what I am seeing immediately is that you’re setting the emmiter on instead of using the emit_particle() function. Wouldn’t that be easier?

Ok, there are two big issues that are gonna cause unpredictable behaviour. First, you’re using _process() instead of _physics_process() so sometimes you’re getting data from the wrong physics frame. Second, you’re changing the velocity of a RigidBody. You should use forces instead. You could set the bounciness in the physics materials instead of calculating it yourself and let the engine figure out the velocity. Only apply an instant force with the player input.

I moved checking collision from _process to _physics_process, and now player input is applying force instead of changing velocity, and set the bounciness in the physics material. But it is even more buggy now

I have pushed changes to github

There are still some outstanding issues:

  • Your parabola preview is inaccurate when the ball is in motion because it doesn’t update the original position, but it updates the release position.
  • The way you make the level collision using the tileset means there is a square for every tile. This means the ball sometimes bounces on a corner where you see a flat surface. This can only be fixed by making the collision shapes without the default automation.