Hey! I’m using godot 4 and I can’t seem to find my variables in remote! I’ve seen different tutorials and all that but they don’t work, I just wanna see my velocity.x in my CharacterBody2D for debugging purposes! Any solutions?
would those tutorials perhaps be outdated or something?
Character body’s velocity property is not supposed to be altered in the editor so it won’t show in the inspector. The simplest way to see it is to just copy its value to a custom property every frame.
i cant see any of the other variables though… and even when i do that, i cant see that variable!
this is the code i used
var xvelocity = velocity.x
Did you put a export before the variable?
You can’t see local variables, only class properties, so declare xvelocity outside of any function to make it a class property and assign velocity to it in _process().
thank you
oh wait edit but i just realized it doesnt update the x and only the y for some reason
should i share my whole script?
Well you only assign x in the code you posted: xvelocity = velocity.x. Let the property be a vector.
var velocity_shadow: Vector2
func _physics_proocess():
# your regular code
velocity_shadow = velocity
extends CharacterBody2D
@export var xvelocity: Vector2
func _ready() -> void:
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta: float) -> void:
if globalvars.can_use_gravity:
xvelocity = velocity
velocity.y += globalvars.custom_gravity
if globalvars.can_move_left:
if Input.is_key_pressed(KEY_LEFT) or Input.is_key_pressed(KEY_A):
velocity.x = -500
if Input.is_key_pressed(KEY_LEFT) and Input.is_key_pressed(KEY_SHIFT) or Input.is_key_pressed(KEY_A) and Input.is_key_pressed(KEY_SHIFT) and globalvars.stamina > 0:
velocity.x -= 100
globalvars.stamina -= 7
if globalvars.can_move_right:
if Input.is_key_pressed(KEY_RIGHT) or Input.is_key_pressed(KEY_D):
velocity.x = 500
if Input.is_key_pressed(KEY_RIGHT) and Input.is_key_pressed(KEY_SHIFT) or Input.is_key_pressed(KEY_D) and Input.is_key_pressed(KEY_SHIFT) and globalvars.stamina > 0:
velocity.x += 100
globalvars.stamina -= 7
if globalvars.can_use_jump:
if Input.is_key_pressed(KEY_UP) and is_on_floor() or Input.is_key_pressed(KEY_W) and is_on_floor() or Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and is_on_floor():
velocity.y = -1000
if Input.is_key_pressed(KEY_A) and Input.is_key_pressed(KEY_D):
velocity.x = 0
elif Input.is_key_pressed(KEY_LEFT) and Input.is_key_pressed(KEY_RIGHT):
velocity.x = 0
move_and_slide()
velocity.x = 0
if velocity.x > 750:
velocity.x = 750
elif velocity.x < -750:
velocity.x = -750
globalvars.stamina += 5
if globalvars.stamina > 100:
globalvars.stamina = 100
elif globalvars.stamina < 0:
globalvars.stamina = 0
heres my actual new code i mean
even if i update the value of velocity.x in the inspector, that doesnt even update it!
What exactly are you aiming to achieve? velocity is not supposed to be edited in the inspector, only through code.
so thats not what i was trying to do, but really i want to see if the velocity changes with this sprinting code, just testing cause to me when i run the game it doesnt LOOK like it but it might be and might not be looking like it
You can always just do print(velocity) for a quick feedback.
If you want to use a shadow variable, you should do it as in my example. Put xvelocity = velocity at the end of _physics_process() outside of any if blocks`, so it updates every frame regardless of any conditions.
for some reason when i did that before it just printed 0.0
Post that code.
all i did was print(velocity.x) out of any if blocks but inside _physics*_*process()
If that printed 0.0 then velocity.x was indeed zero.
but i was moving! when i moved it printed 0.0 and kept printing 0.0 but for some reason it was really higher
