Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | 3.141592653589 |
Here is the code
So im working on a shooter game and its my first one and im trying to make a ennemy that follows the player but im really struggling because instead of following the player it keeps the distance it innitially had with the player pls help
extends KinematicBody2D
var speed = 200
var motion = Vector2.ZERO
var player = null
func _physics_process(delta):
motion = Vector2.ZERO
if player:
motion = position.direction_to(player.position) * speed
motion = move_and_slide(motion)
func _on_Area2D2_body_entered(body):
player = body
func _on_Area2D2_body_exited(body):
player = null
try
var velo = Vector2.ZERO
func _process(_delta):
var target = $node_target.global_position
var rot = (target - $point.position).normalized()
if $point.position.distance_to(target) >= 10:
$point.position += rot * velo
pass
ramazan | 2022-01-24 08:06
Ok so there is one thing i don"t get what do you mean by point
3.141592653589 | 2022-01-25 02:53
$point = $Player etc. ==> $node_name
ramazan | 2022-01-25 07:36