How to make an arrow point in a direction, circling around a circle, based on two vectors

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By paradisegames
:warning: Old Version Published before Godot 3 was released.

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?

:bust_in_silhouette: Reply From: timoschwarzer

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_child(arrow)
arrow.hide()

Add this to the input down event:

arrow.show()

Add this to the input move event:

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

Add this to the input up event:

arrow.hide()

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

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

rafah | 2019-01-23 17:51