Godot Version
4.2.1
Question
Seems like I can’t upload any videos so I’ll just redirect you to Reddit where I first uploaded this question:
Reddit Post with the bug and code
Player attract enemy code:
func attract_to_player(delta):
# Accelerate towards player
curEatSpeed = lerp(curEatSpeed, eatSpeed, eatAccel * delta)
# Calculate direction towards player
var direction = (player.position - position).normalized()
# Smooth movement out
var curveDir = direction.lerp((player.position - position).normalized(), eatCurve)
position += curveDir * curEatSpeed * delta
# Make enemy smaller over time
var distPlayer = position.distance_to(player.position)
var scaleFactor = clamp(distPlayer / 200.0, 0.5, 1.0)
scale = scale.lerp(Vector2(scaleFactor, scaleFactor), 0.1)
Enemy instantiate code:
func other_function(): # Not the real function, just a slice of it
var enemyInstance = get_enemy(enemyType)
# Spawn
enemyInstance.position = get_lane(lane)
enemyInstance.handedness = handedness
add_child(enemyInstance)
func get_enemy(enemyType):
var enemy
match enemyType:
"BaseEnemy": enemy = BaseEnemy.instantiate()
return enemy