Alternative for "move_and_collide"?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Paul Wetzel

Hey there, I am currently working on an enemy, which inherits from a regular node. I wanted to use move_and_collide to create the movement, but as my enemy does not extend KinematicBody2D, I cannot use it. Does anybody maybe know an alternative to this?

Is there a reason it inherits from a regular node instead of KinematicBody2D? If not, I recommended changing its parent type to KinematicBody2D and that will let you use move_and_collide

godot_dev_ | 2022-09-27 14:47

:bust_in_silhouette: Reply From: SteveSmith

Move the enemy manually by adjusting their position, and give them an Area2D to check for collisions.

:bust_in_silhouette: Reply From: Wakatta
# move_towards
func _process(delta):
    if (target - position).length() > 2:
        position = move_toward(target, delta * move_speed)

# lerp
func _process(delta):
    if (target - position).length() > 1:
        position = lerp(position, target, delta)