Hello,
So I'm new to Godot (and programming) and I'm trying to make a very light football game prototype. Right now, what I'm trying to do is to wait for a given amount of time, then trigger a function to move the ball from point A to point B. Nothing fancy.
My issue is that the Tween animation of the ball doesn't work and nothing happens.
My code is structured that way:
I have a Clock Node which contains this script:
extends Node
var second = 0
var minute = 0
var time_mult = 250.0
var paused = false
var Match = load("res://Match.gd").new()
func _ready():
set_process(true)
func _process(delta):
if not paused:
second += delta * time_mult
minute = int(second / 60)
get_node("MarginContainer/Label").set_text(str(minute))
if minute == 3:
Match.kick_off()
My Match.gd is supposed to centralize every action and call the appropriate functions. Here's what it looks like for now:
extends Control
var Ball = load("res://Ball.gd").new()
# Called when the node enters the scene tree for the first time.
func _ready():
print("Match started!")
func kick_off():
Ball.move_to()
And so the idea is that after 3 minutes, the kick_off is triggered, which triggers the Ball Node to move to a specific point.
Here is my Ball.gd:
extends Node2D
onready var TweenNode = get_node("Tween")
func _ready():
var x = get_viewport().size.x/2
var y = get_viewport().size.y/2
self.position = Vector2(x,y)
func move_to():
TweenNode.interpolate_property(self, "position", get_position(), Vector2(125,78), 1.0, Tween.TRANS_LINEAR, Tween.EASE_IN)
TweenNode.start()
print("Moved")
What I don't understand is that the console does print "Moved" so the function is indeed triggered correctly. But it gives me this error:
Invalid call. Nonexistent function 'interpolate_property' in base 'Nil'.
I figure this has something to do with me not understanding correctly the relations between the different scripts but I can't seem to find the answer.