0 votes

Hi,

I have a enemy that extends KinematicBody2D as a node. So I added two CollisionShape2D, one in the head , other in the body.

Is it possible to detect if the collision was on the body or on the head ?
Is it possible to check the inside fixedprocess function?
Is it possible to check the collsion inside Enemy's fixedproces function, instead player's one?

enter image description here

#Player's KinematicBody2D 

func _fixed_process(delta):

  if is_colliding():            
    print(get_collider())
    pass
in Engine by (19 points)

1 Answer

+1 vote
Best answer

Sadly there is no direct method to get the own shape that collided on KinematicBody2D, collider refers to the other body that was hit when using move.

In this case, if the player hits enemy, the player can get_collider_shape of the enemy but the enemy can only get_collision_pos and try to guess where it was (or use Physics2DDirectSpaceState and test the collision point).

by (7,946 points)
selected by

@eons,

I get it done by spliting the body and head in separated areas.
Than connect the function in enemy's script.

It works! =D

enter image description here
enter image description here

if the area is bigger, it should work, also you can use KinematicBodies as sub-bodies but these will be moved as static bodies by the main body (ignoring overlaps), if enemy head works as a platform, it can be used this way without affecting the main body move (the head will ignore contact too).

good to know @eons, thanks!!

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.