Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Logan McDaniel |
I’ve been trying to figure this out for hours and the only information I can find is in these Q&As. I can’t really find anything in the docs either and its driving me insane.
I’m quite new to programing and all I was trying to do is mess around and get a feel for the engine. I’m trying to send my KinematicBody2Ds velocity to a RichTextLabel so that I can check its velocity in-game instead of through the output console. My problem seems like something so simple and vital to creating games yet everything I’ve tried hasn’t worked.
I’m not sure what to do right now, there has to be a simpler way of doing things instead of using get_node which I can’t find any useful information about outside of those forum posts. Every time I try using get_node a number of errors appear and every time I change something a different error appears. The most plausable explanation I can come up with is that I’m doing something wrong on the KinematicBody script so I’ll post it here.
extends KinematicBody2D
var x = 0
var y = 0
var velocity = Vector2()
func _ready():
pass
func _process(delta):
velocity = Vector2(x, y)
if Input.is_action_pressed("ui_up"):
if y > -100:
y = y - 10
elif velocity.y < 0:
y = y / 1.1
if Input.is_action_pressed("ui_down"):
y = y + 5
elif velocity.y > 0:
y = y / 1.1
if Input.is_action_pressed("ui_right"):
x = x + 5
elif velocity.x > 0:
x = x / 1.1
if Input.is_action_pressed("ui_left"):
x = x - 5
elif velocity.x < 0:
x = x / 1.1
if y != 0:
if y < 1:
if y > -1:
y = 0
print(y)
print(velocity)
velocity = move_and_slide(velocity)
return y #i thought this might do something, probably not though
pass
I finally found my problem after hours of trying, and it is something Godot should fix. Whenever I copied a node path I assumed it was the proper node path, as it would just make sense that when you copy a node path that node path should be the proper node path and it should just be a copy and paste into anything that needs it. I was wrong as I needed to add “…/” before what I copied for it to work. I don’t know if there’s a specific reason that Godot doesn’t give you the proper node path but if there really isn’t it seems like quite a major issue for beginners.
Logan McDaniel | 2020-07-03 20:19