#Enemies on godot

1 messages Β· Page 1 of 1 (latest)

granite shard
#

I'm working on a game on godot and i want to add enemies. I want them to run to the player when they see the player. How do i do it?

novel elk
#

I guess you could reference a Collision object in the script and a raycast that always points at the player,

write a function that checks if the raycast is hitting the player directly and is inside the other Collision object (that way you can have a cone of vision, and the enemy will move only if both are colliding with the player

If so, it'll move to player using this
`
var current_location = global_transform.origin
var next_location = Nav_Agent.get_next_path_position()

var new_velocity = (next_location - current_location) * Speed
velocity = new_velocity`
granite shard
#

thanks

#

ill try it