How to check if a player is not colliding

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

Hi
I have a KinematicBody2D player node in which I want to check ‘if the player is not colliding with anything, run code’ but I can’t figure out how. I am new to Godot so detailed explanations will really help me out. Thanks in advance

:bust_in_silhouette: Reply From: Gluon

I havent used this myself but if you use the code

if not is_colliding():
    do your code here

this should work. You could put this in

func _process(delta):

which will automatically run each frame so you will always be checking. This will take up processing time each frame though so I dont know if this will slow down the game at all.

Sorry I should also have mentioned this will only work in a script on a node with the is_colliding(): function built in so for instance have raycasts in your player scene which can detect contact.

Gluon | 2022-03-08 08:09