Andicraft/stairs-character

Not working, player does not move

Closed this issue · 6 comments

Hello and sorry to bother. This addon doesn't seem to work for me. I changed it accordingly and I printed desired_velocity and it changes, but the character doesn't move

`extends StairsCharacter
class_name Player

@export var walk_speed := 4.0
@export var walk_backwards_speed := 1.5
@export var walk_sideways_speed := 1.1
@export var sprint_multiplier := 1.5
@export var acceleration := 15
@export var deacceleration := 10
@export var JUMP_VELOCITY := 3.5
@export var stamina_component : StaminaComponent

var gravity = 10
var input_dir : Vector2

enum MOVEMENT_TYPE {
IDLE,
WALK,
RUN
}

@onready var current_state : MOVEMENT_TYPE = MOVEMENT_TYPE.IDLE

func _physics_process(delta):
if not is_on_floor():
velocity.y -= gravity * delta

if Input.is_action_just_pressed("jump") and is_on_floor():
	velocity.y = JUMP_VELOCITY

input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()

if direction:
	if Input.is_action_pressed("sprint") and input_dir.x == 0 and input_dir.y < 0 and stamina_component.has_stamina: 
		current_state = MOVEMENT_TYPE.RUN
		direction *= sprint_multiplier # if pressing sprint and not moving backwards
		stamina_component.drain()
	else:
		stamina_component.stop_drain()
		current_state = MOVEMENT_TYPE.WALK
	
	if input_dir.y > 0: # if going backwards move slower
		velocity.z = move_toward(velocity.z, direction.z * walk_backwards_speed, delta*acceleration)
	else:
		velocity .z = move_toward(velocity.z, direction.z * walk_speed, delta*acceleration)
	
	if abs(input_dir) == Vector2.RIGHT: # is going only left/right use sidewayys speed
		velocity.x = move_toward(velocity.x, direction.x * walk_speed, delta*acceleration)
	else:
		velocity.x = move_toward(velocity.x, direction.x * walk_speed, delta*acceleration)
	
else:
	current_state = MOVEMENT_TYPE.IDLE
	velocity.x = move_toward(velocity.x, 0, delta*deacceleration)
	velocity.z = move_toward(velocity.z, 0, delta*deacceleration)

desired_velocity = velocity.normalized()
move_and_stair_step()
#move_and_slide()

func _input(event):
if Input.is_action_just_pressed("ui_cancel"):
#get_tree().quit()
toggle_mouse_mode()

func toggle_mouse_mode():
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
else:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

`

This is also my player controller, should have also sent it earlier

image
image
Added also these for more context

The player does move but doesn't move up the stairs

just add super(delta) in your _physics_process

"super() is used to call the parent's class method from within the child overriding method." - info

That worked! Thank you!