Godot Version
4.3.stable.steam
Question
I’m attempting to make a pushable box via using the RigidBody2d node. Currently I have the following code located in my player’s script (who’s base node is a CharacterBody2d):
var pushForce = 50
if body.move_and_slide(): # true if collided
for i in body.get_slide_collision_count():
var col = body.get_slide_collision(i)
if col.get_collider() is RigidBody2D:
col.get_collider().apply_central_force(-col.get_normal() * pushForce)
While this code does work to push the boxes, I’m running into several issues with this approach, primarily that the player can go well beyond their normal speed while continuously pushing on the box, effectively being stuck to the box while pushing.
I’ve tried all 4 different “apply_force()” methods for a RigidBody2d [That is, apply_force(), apply_impulse(), apply_central_force(), and apply_central_impulse()], and each of them replicate this behavior. I’ve also tried adjusting pushForce
to various values, but even very small values can still replicate this behavior.
What could be causing this, and what could be done to amend this?
p.s. If anyone knows how I can upload a video to the forums to show the above behavior, please let me know.