This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello to everyone,

I have an object made of several KinematicBody2D parts, since some parts need separate rotations and/or animations (imagine a level boss to be intended).

I need simply to stop the object from moving (the entire tree of KinematicBody2D object parts) if one of them touch an obstacle. Currently, every object part has his moveandcollide() method called in the physicsprocess() method, and what succeeds now is that while the colliding object part correctly stops moving when a collision occurs, the other parts still move, breaking the whole thing.

Basically, how I can synchronize every object parts that if just one part collides and stops all the remaining should also stop? The best way? Hoping to have explained decently the problem, I'm very glad for suggestions. Thanks!!

in Engine by (24 points)

1 Answer

0 votes

I just solved the question in the following way, for now it seems without any contraindication:

Firstly, my set of KinematicBody2D parts is composed of this simple hiearchy:

LevelBoss
--------Part01
--------Part02
etc etc...

The physicsprocess() function of LevelBoss I checked is called always for first by Godot, but to move the LevelBoss i must know if some of its parts (Part01, Part02, etc...) collides with obstacles.

So, in the LevelBoss physicsprocess() I simply call for every part a CheckCollision() method, passing it the delta time, this is my simple CheckCollision():

func CheckCollision(delta):
if (test_move(global_transform, velocity * delta)):
    get_parent().StopMove()

here the StopMove() simply sets a flag in the parent (the LevelBoss) to inform he can't move. But If no parts calls StopMove(), LevelBoss finally moves by simply calling in its physicsprocess() :

move_and_collide(velocity * delta)

This was my natural way to handle an object composed of different KinematicBody2D parts, if you have suggestions to improve the code they are welcomed!

by (24 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.