Godot Version
4.4
Question
Hello, i have an issue with the area entered function not working specifically with the player character not registering the collision with the enemy but what really confuses me is that the slime registers the player area and can even recognize that its from the group player so at this point im lost all the mask and layers match and ive tried everything. Here are the relevant codes and screenshots any help would be appreciated
and here is the relevant code:
```extends CharacterBody2D
const SPEED = 130.0
const JUMP_VELOCITY = -100.0
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
func _on_area_2d_area_entered(area: Area2D) -> void:
if area.is_in_group("Enemy"):
print("its a slime")
print("collision")
extends Node2D
const SPEED = 60
var direction = 1
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
@onready var ray_cast_right: RayCast2D = $RayCastRight
@onready var ray_cast_left: RayCast2D = $RayCastLeft
func _process(delta: float) -> void:
if ray_cast_right.is_colliding():
direction=-1
animated_sprite_2d.flip_h=true
if ray_cast_left.is_colliding():
direction=1
animated_sprite_2d.flip_h=false
position.x += direction * SPEED * delta
func _on_area_2d_area_entered(area: Area2D) -> void:
if area.is_in_group("Player"):
print("Its a player")
print("collision")