Need Help Making A KinematicBody2D Push Another Body

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

I’m currently experimenting with the Godot Engine and I’m currently trying to make the player (made by a KinematicBody2D) push a “box” node. While pushing the player should slow down. Should I be using a Static or a Kinematic body for the box?
If it’s static then how much work does the physics engine save me? Do I still need to code the player’s movement slowing down while pushing?
If it’s the Kinematic body then I’m pretty sure I should put an area around the player and check if it is overlapping with the box and then make the box move…
But in order to do that which node should I use for the “push area”? The Area2d node right? Then how do I check if the area is overlappign the “box” node? How do I fetch the x coordinates of the box and the player in the same script? Should I be attaching a general Node to fetch the coordinates and see if the player is on the right side or left side of the box? If that’s so than how do I send the result (left/right) to the box node in order to make it move left or right?

I’m sorry if these questions are very basic, this is my first time working with a game engine like this.

I’ll attempt to go through the questions in order.

For the box, I’d personally go with a RigidBody2D, as a StaticBody2D would be more appropriate for immovable objects. A StaticBody2D won’t be moved, but can impart some force on the more movable RigidBody2D.

For the “pushing slowing the player down”, you’d check which body the KinematicBody2D’s Area2D is touching, and reduce the speed the character can move. This would include a small if/else block in your movement section, where IF the player is pushing against the block, speed is reduced, otherwise (a.k.a. ELSE), movement is normal.

The move_and_slide() method may help, in case your character needs to go around the box, and/or jump over it. I think there’s something you can do to check the direction the player is going, and if there is a box immediately in the way, too.

It’s okay if these questions are basic. Everyone’s a beginner at some point. It can help some of us help you if you show a little of your code. Perhaps letting us see what’s in the and your box’s scripts will help.

System_Error | 2019-10-23 22:41