0 votes

First, I new to Godot. So I make a simple top-down game and I have one thing that still confuses me. Let's say I have a Player Node that have an area2D and I want when my enemies heading to my area and I press button, my Player can dash into the target. But I don't get it how to code that thing. How can I get the enemy position and how can I dash to enemy position?

Godot version 3.3.4
in Engine by (29 points)

1 Answer

+1 vote
Best answer

In order to get the enemy position, you need to get the node path for to the enemy. This explains how node paths work. Once you have the node path, you can just get the position property of the enemy (like enemy.position or so).

For dashing, you probably want to set a state on the player so that it can't do anything else while dashing. So have variable like is_dashing or so. In the _physics_process function have the player move toward the enemy position using Vector2.direction_to().

by (8,150 points)
selected by

thanks! it very helpful.

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 Frequently asked questions and 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 [email protected] with your username.