A code error in Godot 3

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

const PLAYERSPEED = 100
const INITBALLSPEED = 100

var screenSize
var padsize
var ballDirection = Vector2(1.0, 0.0)
var ballspeed = INITBALLSPEED


func _ready():
	screenSize = get_viewport_rect().size
	padsize = get_node("rightplayer").get_texture().get_size()
	set_process(true)
	pass

func _process(delta):
	
	if(get_node("rightplayer").position.y > 18 and Input.is_action_pressed("ui_up")):
		get_node("rightplayer").position.y += -PLAYERSPEED * delta
	if(get_node("rightplayer").position.y < 382 and Input.is_action_pressed("ui_down")):
		get_node("rightplayer").position.y += PLAYERSPEED * delta
	
	if(get_node("leftplayer").position.y > 18 and Input.is_action_pressed("left_up")):
		get_node("leftplayer").position.y += -PLAYERSPEED * delta
	if(get_node("leftplayer").position.y < 382 and Input.is_action_pressed("left_down")):
		get_node("leftplayer").position.y += PLAYERSPEED * delta
	
get_node("Ball") += ballDirection * ballspeed * delta

Hi Friends I am using Godot 3. There’s a mistake here.

get_node("Ball") += ballDirection * ballspeed * delta

help me

:bust_in_silhouette: Reply From: kidscancode

That line doesn’t make sense. get_node("Ball") retrieves a reference to the “Ball” node, and then you’re trying to add to it with +=

You probably want

get_node("Ball").position += ballDirection * ballspeed * delta

Thank you. Working successfully

CarelPersonne | 2019-08-21 05:25