How a non moving KinematicBody2D can detect collision ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DriNeo
:warning: Old Version Published before Godot 3 was released.

Hi. You can try this example script on two Kinematic bodies.

extends KinematicBody2D

export var Velocity = Vector2() 

func _ready():
	set_fixed_process(true)
	pass

func _fixed_process(delta):
	if is_colliding():
		if get_collider() extends KinematicBody2D:
			set_opacity(0.5)
	
	move(Velocity.normalized() * 20 * delta)

Set the velocity of a single body in order to hit the other. You will notice the non moving body doesn’t change his opacity. Even if “move” function is called everytime.

I can keep my code simple if each kinematic body is able to detect collisions by himself, even if the velocity is null.

:bust_in_silhouette: Reply From: eons

is_colliding must be called after move methods.

A better way to do this without constantly moving (0,0) is to make the body who collides to tell the stationary KB that was hit by something (can use group checks to be sure that is a body that can react to collisions).

I tried with the move call before is_colliding without success.
Like you said, I’m temporarily using a communication between bodies to make this thing work.

DriNeo | 2017-12-28 18:01