0 votes

Here's the situation i have:

I have a ball (2D), and an arrow.

In the game, the player touches the screen, and drags their finger. When the finger is lifted, the game subtracts the two vectors (finger down, finger up) and launches the ball in the opposite direction of the invisible "line" drawn by the finger.

I want to have a pointer arrow show the direction the ball is going to fly in.

I want the arrow to circle around the ball, like a north arrow on a minimap for example, and show the direction the ball will fly.

How would I go about doing this?

in Engine by (12 points)

1 Answer

+1 vote

Create a new scene called Arrow.tscn consisting of a simple Sprite with an arrow texture or a Polygon2D.

Add this to the top of your script:

const Arrow = preload("Arrow.tscn")
var arrow = null

Add this to _ready():

arrow = Arrow.instance()

Add this to the input down event:


Add this to the input move event:

arrow.set_rot((finger_pos - finger_down).angle())

Add this to the input up event:


This should show an arrow pointing in the target direction when dragging your finger.

by (711 points)

Hello sir, this is very useful, but dont seems to work on newest godot, could you suggest anything for a noob?

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.