Godot Version
` 4.4.stable
Question
` Thank you in advance for your attention to my problem.
I was following Brackey’s video “How to make a Video Game - Godot Beginner Tutorial”, and it made me want to continue learning about Godot.
I tried to ensure that my enemies (different instances of the Slime scene) wouldn’t collide with each other and turn around when they crossed paths with one of their peers by adding my “Slime” scene (Node2D) to a global “slime” group and using the “is_in_group” method.
However, if collisions with the TileMap are always detected by the various Raycast2Ds (right and left), it would seem that the “is_in_group” method simply doesn’t work, because when I use the print method to display the collisions detected, it only shows me objects relating to the TileMap.
extends Node2D
const SPEED = 60
var direction = 1
@onready var raycast_right: RayCast2D = $RaycastRight
@onready var raycast_left: RayCast2D = $RaycastLeft
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float):
if raycast_right.is_colliding():
var collider_right = raycast_right.get_collider()
if is_instance_valid(collider_right):
if collider_right is TileMap or collider_right.is_in_group("slimes"):
direction = -1
animated_sprite.flip_h = true
print(collider_right)
elif raycast_left.is_colliding():
var collider_left = raycast_left.get_collider()
if is_instance_valid(collider_left):
if collider_left is TileMap or collider_left.is_in_group("slimes"):
direction = 1
animated_sprite.flip_h = false
print(collider_left)
position.x += direction * SPEED * delta
I’m aware that my code won’t be perfect and may even be highly debatable, which is why I’m relying on you to understand my mistakes and learn how to use Godot better. I apologize in advance if my message is not clear, as English is not my native language.
`