#My enemy (green slime) will not chase my player(player)?

1 messages · Page 1 of 1 (latest)

dreamy verge
#

your slime code does get_parent() as Charbody

#

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;

  1. have the player add_to_group("player") in its func _enter_tree(): (which is like ready, but runs even earlier)

  2. and have the slime find it not by saying get_parent() as CharacterBody (which is more or less what it's doing now) but instead get_tree().get_first_node_in_group("player") as CharacterBody

wise agate
#

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.

dreamy verge
#

oh sneaky, that's even better than my fix for your situation, OP! 🙂

wise agate
#

I'm not familiar enough with groups, but I use class_names everywhere I go 😅

dreamy verge
#

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 🙂

unkempt seal
#

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*

wise agate
#

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

unkempt seal
#

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

edgy field
#

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?

edgy field
unkempt seal
#

i found a solution, thanks for the help. How do i close this?

dreamy verge
unkempt seal
#

wait like?

#

☑️

#

☑️

#

#

uhhh

dreamy verge
#

right now we're just having a lovely conversation 🙂 I already tagged the emoji. are you on desktop, or just mobile?

#

(anyway: it's also popular to thank the hosts and slink away. Lots of solved posts aren't tagged because it is an unrewarding UI interaction 🙂 )