Godot Version
4.2.2
Question
So I set this enemy to charge at the player. However it goes through walls in my tilemap. Here’s my code:
extends CharacterBody2D
var ACCELERATION = 1500
var FRICTION = 600
var SPEED = 1000.0
var SPEEDLESS = 200.0
var loopy = 3
var goofy = 1
var othergoofy = 0
var stop = true
var dizzy = 0
var motion = false
var breaking = false
var motionstart = false
var motionend = false
@onready var player = get_parent().get_node("Player")
@onready var playerpos = global_position.direction_to(player.global_position)
@onready var rng = RandomNumberGenerator.new()
@onready var my_random_number = rng.randf_range(1, 100)
func _process(delta):
pass
func _physics_process(delta):
if motion == true:
$AnimationPlayer.play("rollrollypoly")
elif motionstart == true:
$AnimationPlayer.play("startrollypoly")
elif motionend == true:
$AnimationPlayer.play("endrollypoly")
elif breaking == true:
$AnimationPlayer.play("dizzyrollypoly")
else:
$AnimationPlayer.play("idlerollypoly")
if stop == false:
motion = true
global_position.x += (playerpos.x * SPEED) * delta
global_position.y += (playerpos.y * SPEED) * delta
await get_tree().create_timer(1).timeout
motion = false
motionend = true
await get_tree().create_timer(0.45).timeout
motionend = false
stop = true
elif stop == true and my_random_number < 2:
playerpos = global_position.direction_to(player.global_position)
breaking = true
await get_tree().create_timer(1).timeout
motionstart = true
await get_tree().create_timer(0.45).timeout
motionstart = false
breaking = false
stop = false
else:
playerpos = global_position.direction_to(player.global_position)
await get_tree().create_timer(1).timeout
motionstart = true
await get_tree().create_timer(0.45).timeout
motionstart = false
stop = false
pass
move_and_slide()