Tryin to add arrow to a ball before launch I wet an error:

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GamelandX

Hi all, I been trying to add an arrow, but no matter what I try Im still unable, at this momnet it is erroring out at line 28, but maybe someone with more experience can tell me where am I really making my mistake, any help is appreciated:

This is the error: Invalid call to function ‘get_rotation’ in base ‘Node2D’. Expected 0 Arguments

extends RigidBody2D

var dragging
var dragstart = Vector2()
var dragend = Vector2()
var launched = false
var trys= 3
const Arrow = preload('res://scenes/Player/Arrow.tscn')
var arrow = null
var dir

func ready():
arrow = Arrow.instance()
addchild(arrow)
arrow.hide()

func input(event):
if (trys != 0):
if event.isactionpressed("click") and not dragging and not launched:
dragging = true
dragstart = getglobalmouseposition()
if event.isactionreleased("click") and dragging:
dragging = false
launched = true
trys -= 1
arrow.show()
arrow.getglobalmouseposition()
arrow.getrotation(dir).angle()
dragend = getglobalmouseposition()
dir = dragstart - dragend
applyimpulse(Vector2(), dir * 5)
arrow.hide()
yield(gettree().createtimer(5.0), "timeout")
launched = false
:bust_in_silhouette: Reply From: kidscancode

FYI, you lost all the _ symbols from your code, I’m guessing through some kind of copy-and-paste issue.

get_rotation() doesn’t take any arguments, it returns an angle. However, you wrote:

arrow.get_rotation(dir).angle()

So you’re getting an error because you have dir in there. Also, since get_rotation() returns an angle, you can’t call angle() on it. angle() is a Vector2 method.

In addition both of these lines, even if they worked:

arrow.get_global_mouse_position()
arrow.get_rotation(dir).angle()

Would do nothing because you’re not saving the return values. Since you have:

dragend = get_global_mouse_position()

just a few lines down, and you are saving it into a variable, there’s no need to find the mouse position more than once.

Aside from that, it’s a bit difficult to figure out what you’re trying to do because of the messed up code formatting. All the indentation is lost, for example. Please edit your post and re-paste the code. Use the “Code Sample” button at the top of the edit box to format it.