0 votes

Hi Everyone,

I am having trouble with path2Ds. So the enemies spawn at intervals as per the "your first game". However, what I want is for them to spawn and move towards/go to a stationary character or a set of coordinates from wherever they spawn.

I have tried a bunch of stuff and can't get it to work. Any ideas?

Code would be appreciated.

(If it makes any difference the player will use a centre of gravity to attract the enemies of their path - would I need to define a new path so that they don't continue to go back to the hub immediately, but after a certain time?)

func _on_MobTimer_timeout():
$Path2D/PathFollow2D.offset = randi()
var mob = Enemy.instance()
add_child(mob)
var facing = $Hub.position
var direction = facing.rotation
mob.position = $Path2D/PathFollow2D.position
mob.linear_velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0)
mob.linear_velocity = mob.linear_velocity.rotated(direction)

Thanks.

Godot version 3.0
in Engine by (14 points)

To be clear, you called randomize() right? What do you mean when you say you can't get it to work? Have you read this article?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.