Player not moving because of Vector2

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

So i was trying to recreate the snake game on godot to gain familiarity with the software and based on tutorials and the documentation, i wrote this script
`extends CharacterBody2D

var speed = Vector2()
var health = 1

func _physics_process(_delta):
if Input.is_action_pressed(“move_right”):
speed.x = 1
if Input.is_action_pressed(“move_left”):
speed.x = -1
if Input.is_action_pressed(“move_down”):
speed.y = 1
if Input.is_action_pressed(“move_up”):
speed.y = -1`

When i replace the speed with print(“”) the input seems to work just fine but with the speed variable it doesnt function properly at all. I already tried changing the code a bunch of times and even copy the moviment script from tutorials n documentation to no effort.

:bust_in_silhouette: Reply From: phil535

What do you mean with replacing speed with print?

Is speed ment to be some kind of direction vector?

I only know the velocity property of CharacterBody2D.

Maybe take a look at these code snippets: Tutorial

wow this really helped! i just did some quick changes on the code with the kinematic tutorial and now its a smooth as butter, TY!

BBCKING6969 | 2023-06-27 19:08