Raycast only recognize collision if target is above sender

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

Code:

func _physics_process(_delta):
         var space_state = get_world_2d().direct_space_state
         var raycastResult = space_state.intersect_ray(self.position, actualPlayer.position, [self])

The raycastResult ends up empty when actualPlayer.position.y is below self.position.y.
actualPlayer and self are both on the same collision layer/mask and the raycast does recognize a collision with actualPlayer when actualPlayer.position.y is above self.position.y.

x position doesn’t seem to matter.

:bust_in_silhouette: Reply From: Dontavius

Is "exclude parent " enabled in the inspector of the raycast ? If yes then you need to put the Kinematicbody on the second collision layer. That worked for me

Its not a raycast node but a raycast sent through code.

Nonken | 2022-08-28 08:54

nvm i found the solution. The position of the player was slightly above the players collider so when the enemy sent the raycast it stopped right before the player collider unless it was sent from below because then it would have to pass through the collider to get to the player position.

Nonken | 2022-08-31 18:58