How can I push an object in Godot 4?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GameSchool

Hi!

I have a CharacterBody2D as a playable character, and I want to be able to push an object. Right now, the object i want to push is RigidBody2D. I tried to find tutorials about it in godot 4, but I couldn’t find anything.

Thanks for the help.

1 Like
:bust_in_silhouette: Reply From: aidave

You have to do this manually by finding slide collisions:

		for index in get_slide_collision_count():
		var collision = get_slide_collision(index)

And then push the rigid bodies in code.

Hi, thanks for the response.

While it did help me with the trigger, I still couldn’t make the push itself work.
do you have an example code for that?

Thanks

GameSchool | 2023-04-01 16:59

It depends what you want to do, it may be obvious to you but not to us.

Try using collision.get_collider() and collider.apply_central_impulse()

Or use move_and_collide

PhysicsBody2D — Godot Engine (stable) documentation in English

KinematicCollision2D — Godot Engine (stable) documentation in English

aidave | 2023-04-01 21:25