Hello, I'm new on Godot (I'm French, that's why my English is not perfect)
I'm trying to create a game (top down) where the principle is the same as a Sumo fight, take out your opponent outside a circle. The problem that I met is that if I use KinematicBody2D the characters don't push each other which is the base of the game, I saw then that it could be possible with RigidBody2D but I can't find any way on internet to make it move like this : https://docs.godotengine.org/fr/stable/tutorials/2d/2d_movement.html#rotation-movement . I then searched if it was possible to push a KinematicBody2D with another KinematicBody2D (so that it can be pushed) but I also couldn't find any way.
So I'm stuck here, and my question is if this is possible and especially how I could do this?
Thanks for reading, Noflare
I believe the issue here would be that you are not using collisions. The functions move_and_slide
or move_and_collide
would engage a Kinematic Body to move, and hit other bodies (including Kinematic Body).
However, as soon as you use either function you will realise they don't push each other in the way you need in the question.
move_and_collide
: The moving object will move and if there is a collider (any obstacle), it will stop immediately upon collision and return a KinematicCollision2D
object.move_and_slide
: Takes further action compared to move_and_collide
, the moving object will slide over the collider, treating it like a wall or a floor. Useful for platformer games.In your use case, you have no choice but to control the collision yourself. You can get more info here on KinematicCollision2D here: (en, fr). This could be possibly how you do it:
var collision = player.move_and_collide(direction_vector)
if (!collision):
# No collision occurred
return
else:
# Collided with a wall or player
if (collision.collider == wall)
# if you keep track of wall object as a variable to identify it
# you can have the sumo just stop moving and not process anymore
return
else:
var opponent = collision.collider
# write game logic to move opponent and yourself
return