Just started using godot and i’m not very experienced. I’ve been following this video so far
I’m having trouble getting a response with a mob collision shape and the player.
When the player enters the mobs “detection area” there is no response and I have no clue why.
Here is the code so far. In advance, thank you
extends CharacterBody2D
#gravity
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var player
var chase = false
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
player = get_node("../../Player/Player")
var direction = (player.position - self.global_position).normalized()
if direction.x > 0:
if chase == true:
print("chase")
else:
print("nochase")
move_and_slide()
func _on_playerdetection_body_entered(body):
if body.name == "Player":
chase = true
func _on_playerdetection_body_exited(body):
if body.name == "Player":
chase = false
Hi! Firstly, you can use three backticks (`) at the start and end when writing your code to show it in code format, making it easier to read, this helps people help you!
Secondly, have you copied and pasted everything? I can’t see anything after this bit - if body.name == "Player":
That could be the reason why it’s not working! Another possibility is that the name you’ve given your Player node may be something different, a common mistake beginners make is mixing cases. Maybe you called your player node “player” with a lower case P?
Hi, thanks for the answer
Yeah, in the video the creator uses print() to check if it’s working and hasn’t continued, i suspect the problem is somewhere in the mathematics of the stuff
var direction = (player.position - self.global_position).normalized()
Thanks for letting me know how to show code, it should be updated now
(sorry for not responding about names)
I have triple checked the names of the nodes that are called they should be alright.
yeah, when entering the enemys “detection area” i want it to print so I can check when I’m inside the area and when I’m exiting the area but I’m not getting a response
I’m not getting any error messages, so I’m a bit lost
After changing the code, I get some output (don’t think it’s correct)
My player is in the air and falls with the enemy until they hit the ground
While falling I get “left” outputted but it stops when hitting the ground but no output when entering or exiting the collision shape (circle)
You haven’t connected your Playerdetection node to your frog script. You can see the youtuber do this at 55:11 in your video, you’ll know you’ve done it properly when you see the little signal icon to the right of the PlayerDetection node.