Godot Version
Godot V4.3
Question
Is it they way I have my movement set up or am I missing something?
const speed = 300
const max_speed = 400
const jump = -600
const friction = 400
const gravity = 25
var input = Vector2()
var health = 100
var anim_locked := false
func _ready():
print("ready")
pass
func _physics_process(delta):
input = get_input()
position += velocity * delta
velocity.y += gravity
if input.x == 0.0:
if velocity.x > (friction * delta):
velocity = velocity.normalized() * (friction * delta)
#print("got input")
else:
velocity.x = 0.0
else:
velocity += (input * speed * delta)
velocity = velocity.limit_length(max_speed)
if Input.is_action_pressed("slash"):
$animation.play("attack")
animation_locked("attack", true)
velocity.x = 0
elif Input.is_action_pressed("jump") && is_on_floor():
velocity.y = jump
elif velocity.y < 0:
animation_locked("jump", true)
$animation.play("jump")
elif Input.is_action_pressed("left"):
$animation.play("walking")
$animation.flip_h = true
#print("flipped")
elif Input.is_action_pressed("right"):
$animation.play("walking")
$animation.flip_h = false
#print("walking")
else:
if is_on_floor():
$animation.play("still")
if Input.is_action_pressed("duck") and velocity.x == 0:
$animation.play("duck")
#print("ducking")
elif Input.is_action_pressed("duck") and velocity.length() > 0:
$animation.play("slide")
velocity *= .90
#print("sliding")
if velocity.length() < 75:
velocity.x = 0
$animation.play("duck")
move_and_slide()
func get_input():
input.x = int(Input.is_action_pressed("right")) - int(Input.is_action_pressed("left"))
input.y = int(Input.is_action_pressed("jump"))
return input.normalized()