Need Help Understanding How to Block Movement

Hi everyone,

I did the script to move the skeleton enemy in the same way I did for the player, so assign “velocity = moving_direction * SPEED” and “move_and_collide(velocity * delta)” in the same way I did for the player, making sure to specify the moving_direction and SPEED values at the top, but unfortunately the skeleton doesn’t move at all even though it animates correctly.

Does anyone know what else I am missing?

Pizza Panic Game with Nonfunctional Skeleton

Okay, I figured out why, it’s cause it’s moving to the right when it’s already against a wall, and when I changed the direction it actually moved properly, so now that that detail is all set I am going to work on adding the actual AI, like only turning when it hits a wall and not turning when it sees the player in a straight line, unlike the original AI (this one is more simpler/dumber).

1 Like

Does anyone know how to detect whether an object collides with a StaticBody or CharacterBody?

There doesn’t seem to be any “area_entered” or “body_entered” signal in the list of pre-given/pre-coded signals, and I can’t just use “body_entered” on one but not the other because I want to check whether a CharacterBody touches a StaticBody, which neither has those signals, in particular check whether the Skeleton enemy is touching the wall so I can turn it 90 degrees to the left or right depending on other conditions.

Does anyone know what the proper solution to this is?

Okay, I think I figured it out on this tutorial:

Using Kinematic Body 2D

Okay, right, on the tutorial page it tells me to do it this way word for word for move_and_collide:

# Using move_and_collide.
var collision = move_and_collide(velocity * delta)
if collision:
    print("I collided with ", collision.collider.name)

Unfortunately, I am told “collider” is an invalid index, and here is the full script for the skeleton enemy for reference:

extends CharacterBody2D
class_name Skeleton

var moving_direction = Vector2(0, 1)
const SPEED = 400.0

func _process(delta: float) -> void:
	$AnimatedSprite2D.play()	
	$AnimatedSprite2D.animation = "down"

func _physics_process(delta):
	velocity = moving_direction * SPEED
	move_and_collide(velocity * delta)
	var collision = move_and_collide(velocity * delta)
	if collision:
		print("I collided with ", collision.collider.name)

Does anyone know what I should do instead, because the instructions on the page I linked are very specific about what details you should type?

I Googled the problem some more and learned if I enable contact_monitor it should work, but can’t seem exactly how to trying to Google it some more, at least not without code.

I suppose it’s probably intentional you need code to enable the contact monitor and can’t just do it by clicking a button in the editor, but my question is what should the code look like exactly to detect if a CharacterBody specifically touches a StaticBody specifically?

Thank you in advance.