Object goes wild when pushing down

Godot Version

Godot 4.3

Question

i made a simple character movement script and i have a rigidbody2d in the scene that i want to push around. everything works fine until i try to push it from above. then it acts like the object is weightless. why does this happen and how do i fix it?

	var col = get_slide_collision(i)
		if col.get_collider() is RigidBody2D:
			var push_force = ((PUSH_FORCE * velocity.length() / max_speed) + min_push_force) * scale.x * scale.x / 2 #the bigger the player the easier they push
			col.get_collider().apply_central_impulse(-col.get_normal() * push_force)```

if anyone wants more information let me know

var PUSH_FORCE = 10.0
var min_push_force = 5.0
var max_speed = 100.0

func _physics_process(delta):
    for i in range(get_slide_count()):
        var col = get_slide_collision(i)
        if col.get_collider() is RigidBody2D:
            var push_force = ((PUSH_FORCE * velocity.length() / max_speed) + min_push_force) * scale.x * scale.x / 2
            var direction = -velocity.normalized() # Direction of force opposite to movement
            col.get_collider().apply_central_impulse(direction * push_force)

try this

nope didnt work. i think its because velocity = 0 when the player is touching the object. it only moves sideways

When the CharacterBody2d is set to “Grounded” motion mode it will snap to floors just beneath it. Maybe you need “Floating”?

1 Like

omg thank you so much :sob: :sob:
cant believe it was that easy

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.