CharacterBody2D / RigidBody2D collision
Asked Answered
P

2

0

Hello,

I have a CharacterBody2D & a RigidBody2D colliding in a scene (Godot 4.1.2 Stable Mono).
When the RigidBody2D is moving above a certain speed & colliding with the CharacterBody2D, the latter exhibits some kind of kickback / backward jittery movement. Same thing happens when the CharacterBody2D initiates the collision at high speed with the RigidBody2D. The higher the speed, the more this jittery backward movement is visible on the CharacterBody2D.

I have coded the CharacterBody2D to follow the mouse cursor (move_and_slide()) and I use apply_central_impulse() to "push" the RigidBody2D in the opposite direction when a collision occurs between the 2 objects.
I have tried reducing the mass & bounciness of the RigidBody2D but no noticeable effect observed. Same with removing apply_central_impulse() from my CharacterBody2D code.

Any lead on how to remove this jittery kickback movement would be greatly appreciated.
Thank you for reading.

Plumy answered 6/11, 2023 at 10:8 Comment(0)
F
0

Plumy I have coded the CharacterBody2D to follow the mouse cursor (move_and_slide())

Are you doing this in _process or _physics_process? Can we see your code?

Fellowship answered 6/11, 2023 at 18:33 Comment(0)
P
0

Fellowship
My code is in _physics_process.
After further investigation, it turns out the culprit was move_and_slide(). From Godot Docs (about move_and_slide()) :

Moves the body based on velocity. If the body collides with another, it will slide along the other body (by default only on floor) rather than stop immediately. If the other body is a CharacterBody2D or RigidBody2D, it will also be affected by the motion of the other body.

I had to make a slight change to my collision masks to take into account this "side effect" of move_and_slide() but problem fixed now.

Plumy answered 7/11, 2023 at 22:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.