i am using godot version 4.3 and this code was made for version 3, ive tweaked it in every way i could possibly think of and it just wont work
heres the old code that originally worked in version 3:
extends CharacterBody3D
@export var speed = 1.7
@onready var anim = $AnimationPlayer
@onready var animationTree = $AnimationTree
@onready var animationState = animationTree.get("parameters/playback")
func Movement():
if Input.is_action_pressed("ui_up"):
velocity.z = -speed
anim.play("bfwalk")
elif Input.is_action_pressed("ui_down"):
velocity.z = speed
anim.play("ffwalk")
else:
velocity.z = lerp(velocity.z, 0, 0.5)
if Input.is_action_pressed("ui_left"):
velocity.x = -speed
anim.play("lfwalk")
elif Input.is_action_pressed("ui_right"):
velocity.x = speed
anim.play("rfwalk")
elif Input.is_action_just_released("ui_left"):
anim.play("lfidle")
elif Input.is_action_just_released("ui_right"):
anim.play("rfidle")
elif Input.is_action_just_released("ui_up"):
anim.play("bfidle")
elif Input.is_action_just_released("ui_down"):
anim.play("ffidle")
else:
velocity.x = lerp(velocity.x, 0, 0.5)
func _physics_process(delta):
Movement()
set_velocity(velocity)
move_and_slide()
and the code as i currently have it [that doesnt work] in version 4.3:
extends CharacterBody3D
const SPEED = 1.7
const JUMP_VELOCITY = 4.5
var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
@onready var anim = $AnimationPlayer
@onready var animationTree = $AnimationTree
@onready var animationState = animationTree.get("parameters/playback")
func Movement():
if Input.is_action_pressed("move_up"):
anim.play("bfwalk")
elif Input.is_action_pressed("move_down"):
anim.play("ffwalk")
if Input.is_action_pressed("move_left"):
anim.play("lfwalk")
elif Input.is_action_pressed("move_right"):
anim.play("rfwalk")
elif Input.is_action_just_released("move_left"):
anim.play("lfidle")
elif Input.is_action_just_released("move_right"):
anim.play("rfidle")
elif Input.is_action_just_released("move_up"):
anim.play("bfidle")
elif Input.is_action_just_released("move_down"):
anim.play("ffidle")
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir := Input.get_vector("move_left", "move_right", "move_up", "move_down")
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
the movement itself works perfectly fine its literally just the sprite animations that dont work