i have no clue what that means could you give me an example?
My Enemy wont move when starting a my game but i have no errors and includet its movement in my code
So, in your player script at top before extend
write class_name Player
then in your enemy script, in the two func controlling enter/exit at top write if not body is Player: return
this prevents other bodies triggering the func.
I have the problem the last action which is triggert is persue_player but there is no player in the area 2d which the logic can refer to so it stands still
My explanation of guard statement should fix this problem.
The point of a guard statement is to prevent code from triggering if something isnt true. In this case if the body entering/exiting area2d isnt the Player it won’t activate.
i will try this later i have to take a break now but thanks a lot for the help so far
No worries, glad to help, I am just glad we now know what the problem is and how to fix it.
I was thinking your nodes were set up differently so didn’t think about this issue until I saw your node structure.
To chime in here, raycasts do not trigger Area2d
s, they are not collision objects.
What could be happening instead is that the enemy itself (i.e., the CharacterBody2D
) triggers the area.
What is the collision layer of the enemy and the mask of the detection area?
If they match, then when you start the game, you set player
to the enemy itself. When you then set the ‘pursue’ direction it is (0, 0)
, since you are subtracting the position from itself.
If this is the case, then you can, as @regnarok mentioned, fix this by checking if the body is a Player
instance.
But I would also suggest that you update the collsion layer and masks accordingly. It makes it a lot easier to handle collision properly in the future.
Thank you alot everything works like its supposed to now
Thanks for the clarification