]> Untitled Git - knight.git/blobdiff - player/player.gd
Getting the look and feel right
[knight.git] / player / player.gd
index 54b838e7ae210d2acdf0dbefbe3f442b6f958744..1c483fa4bf22e5c99ebf689c90e11c98b77b0a04 100644 (file)
@@ -5,13 +5,22 @@ extends CharacterBody3D
 
 
 const SPEED = 5.0
-const JUMP_VELOCITY = 4.5
+const JUMP_VELOCITY = 4.5 * 3
+const FALL_SPEED = 2.0
+
+
+var _last_movement_direction := Vector3.FORWARD
+
+
+func _input(event: InputEvent) -> void:
+       if event.is_action_released("ui_accept"):
+               velocity.y = 0
 
 
 func _physics_process(delta: float) -> void:
        # Add the gravity.
        if not is_on_floor():
-               velocity += get_gravity() * delta
+               velocity += get_gravity() * FALL_SPEED * delta
 
        # Handle jump.
        if Input.is_action_just_pressed("ui_accept") and is_on_floor():
@@ -20,18 +29,19 @@ func _physics_process(delta: float) -> void:
        # 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("ui_left", "ui_right", "ui_up", "ui_down")
-       var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
+       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
+               velocity.z = direction.z * SPEED
+               _last_movement_direction = direction
        else:
-               velocity.x = move_toward(velocity.x, 0, SPEED)
-               velocity.z = move_toward(velocity.z, 0, SPEED)
+               velocity.x = 0
+               velocity.z = 0
 
        move_and_slide()
 
        if is_on_floor():
                _skin.forward(velocity.length())
-               _skin.global_rotation.y = Vector3.FORWARD.signed_angle_to(direction, Vector3.UP)
+               _skin.global_rotation.y = Vector3.BACK.signed_angle_to(_last_movement_direction, Vector3.UP)
        else:
                _skin.fall()