What exactly happens to velocity upon these two objects colliding?

Godot Version

v4.2.1.stable.official [b09f793f5]

Question

I’ve got a simple 2D scene set up with a few static bodies (with CollisionShape2Ds) that form walls and a floor. I’ve placed a CharacterBody2D (with a CollisionShape2D) on the floor and given it a horizontal velocity to send it sliding toward the wall. I’ve noticed that when the velocity in the direction of the wall is a higher value (>=17), the velocity is set to 0 when the character body collides with the wall. However, for any value < 17, the velocity sees no change. What’s the deal with this? A limitation with collisions?

When you say sees no change what do you mean?

Concerning collisions there are many variables, physics material, mass and inertia. Shapes of collision body. Shapes of colliding pair. AABB Bounding boxes. Object collision settings. Project Gravity and damping.

I would say it’s probably a quirk with your setup.

If you want to read the source code here it is.

By no change, I mean the character body visually stops moving, but when I print it’s velocity.x value from a script it is still whatever value < 17 I had set it to originally. It doesn’t get set to zero like I expect and have seen from collisions at higher velocities. As for further details, both shapes are rectangles with no rotation. gravity is 980, but object has no vertical velocity (is sliding horizontally on floor, also a rectangle) Everything else is all default settings. This is a brand new project which I haven’t really done any tweaking to, and I’m just using stock, untweaked collision shapes.

You are using a characterbody? It doesn’t conform to normal physics, you need to define how things work.

If you are using a rigid body, there could be an issue where speed. If it’s too high, the collision will not work right unless the one of the bodies is large enough to detect it to the collision within a given frame.

But since you’re using rectangles, there could be a lot of funny things happening with friction and collusion points. And it’s a lot of stuff. That’s all I can say

How are you creating walls and floors without tweaking them?

Sorry, should have been more specific. By not tweaking, I just meant I haven’t edited their properties aside from position and scale. And as far as the character body goes, aside from it’s rectangle’s position and scale all I’ve really changed is have it move from gravity, and set it’s horizontal velocity to a fixed value in the ready method. Anyway, this isn’t actually going to affect how my game works, just something weird I noticed. If nothing that could cause this behaviour comes to mind then I’ll leave it, not really worth digging into.

1 Like

I would just add if your changing scale, Godot advises that if you change the scale of the collision body over changing the scale of the static or rigid body node.

The other thing is that every physics body has default friction and bounce behaviors (a default physics material). It could be that 17 is the sweet spot. But since you said any number above 17 causes the body to just stop, could be related to the collision detection at that speed and the AABB size to detect the collision within a frame.

These things can be tuned, just depends on your requirements.