#My enemy (green slime) will not chase my player(player)?
1 messages · Page 1 of 1 (latest)
but its parent isn't the player in the tree
(btw, that's good, its parent shouldn't be the player)
discover the player another way? I really like groups for this;
-
have the player
add_to_group("player")in itsfunc _enter_tree():(which is like ready, but runs even earlier) -
and have the slime find it not by saying
(which is more or less what it's doing now) but insteadget_parent() as CharacterBodyget_tree().get_first_node_in_group("player") as CharacterBody
For your current implementation, you are checking if an overlapping body enters or exits the slime's "chase" areas.
You do not need to get an instance of the player at runtime/on ready.
In your player.gd script, at the top of the script, you can add class_name Player
Then, in your slime script, change the player onready line to just read var player:Player
Finally, in your on_enter and on_exit scripts, instead of checking if body == player, check if body is Player; this checks if the CharacterBody2D has the Player script attached to it, effectively, and if it does, returns true. If it is the player, then set player = body and your code should work, I believe.
oh sneaky, that's even better than my fix for your situation, OP! 🙂
I'm not familiar enough with groups, but I use class_names everywhere I go 😅
sometimes it's hard/weird to have an areay that's appropriate for what you want
(like: find the player wherever they are; an infinite collision area would be weird)
or it's not physical (find the battlestate on boot; it's not an autoload and isn't physical; find all bullets still running and despawn them, etc etc)
groups are great for that 🙂
i've tried implementing both of you guys solutions but neither of them are working
i've tried to put a print under the functions for enter and exit area bodies and none of the mare running
them are*
Can you also put a print at the beginning of each of those area functions to prove we are making it in there? In addition, I would also print whatever the "body" is to see what it is detecting. Finally, in the enter_area_body function, don't forget to set player = body if the body is Player so that the slime will have something to chase.
And if possible, please open the signal inspector so we can see which signals you have connected up to your functions
In addition, I would also print whatever the "body" is to see what it is detecting. Finally, in the enter_area_body function, don't forget to set player = body ---> sorry, i dont understand how to do this
if the body is what is being chased then its ment to be the player i think
meant*
i also don't know what the signal inspector is
It's likely that your Area2d signals hasn't been set up. Could you show me screenshots to help me verify if it's correct?
It's the ui to the pic
i found a solution, thanks for the help. How do i close this?
you can change the emoji through the tripledot on desktop to the "solved" tag, though as a hack you can emoji it with the checkbox directly. Glad you got it fixed!