]> Untitled Git - baabarian.git/blobdiff - player/player.gd
* Fixed skin states in process_player
[baabarian.git] / player / player.gd
index 84657ec2db18c6c8a3d4fb61e37c2093a09bed84..7cd2a814d40d300dff9c0cc790c411de57a6ed77 100644 (file)
@@ -35,6 +35,7 @@ class_name Player
 
 var _last_movement_direction := rotation
 var _floor_normal := Vector3.ONE
+var _ground_slope_input := 0.0
 var _camera_input_direction := Vector2.ZERO
 
 enum {CAMERA_MOUSE_INPUT, CAMERA_JOYSTICK_INPUT}
@@ -50,6 +51,7 @@ func _ready() -> void:
        _debug.draw.add_vector(self, "_last_movement_direction", 1, 1, Color(1,0,0,1))
        _debug.stats.add_property(self, "velocity", "length")
        _debug.stats.add_property(self, "_idle_time", "round")
+       _debug.stats.add_property(self, "_ground_slope_input", "round")
        
        _camera_spring.spring_length = camera_distance
        _player_speed = jog_speed
@@ -121,21 +123,20 @@ func _process_player_on_floor(delta: float):
        
        # if we're not stuck, then it's okay to set the velocity
        _floor_normal = get_floor_normal()
-       var ground_angle := move_direction.angle_to(_floor_normal * Vector3(1, 0, 1))
-       #print(str(ground_angle))
-       velocity = velocity.move_toward(move_direction * (_player_speed + ground_angle), acceleration * delta)
+       _ground_slope_input = (PI / 2) - velocity.angle_to(_floor_normal)
+       velocity = velocity.move_toward(
+               move_direction * (_player_speed + _ground_slope_input * _player_speed),
+               acceleration * delta
+               )
        var movement_speed := Vector3(velocity.x, 0, velocity.z).length()
        
        # also, if we're moving, we're not idle
        if move_direction.length() < 0.2:
                if velocity == Vector3.ZERO:
                        _idle_time += delta
-               if _idle_time > idle_timeout:
-                       _skin.set_idle()
        else:
                _last_movement_direction = move_direction
                _idle_time = 0.0
-               _skin.set_grounded()
 
        # if camera is unlocked, rotate whole skin to face movement direction
        var skin_target_angle := Vector3.BACK.signed_angle_to(_last_movement_direction, Vector3.UP)
@@ -158,6 +159,7 @@ func _process_player_on_floor(delta: float):
        # timescale tweaking for fun effect!
        if _player_speed == charge_speed:
                _skin.set_timescale(2.0)
+               
        else:
                _skin.set_timescale(1.0)
 
@@ -165,20 +167,24 @@ func _process_player_on_floor(delta: float):
 func _process_player(delta: float) -> void:
        if is_on_floor():
                _process_player_on_floor(delta)
-       
+               
+               if _idle_time > idle_timeout:
+                       _skin.set_idle()
+               else:
+                       _skin.set_grounded()
+                       
                _dust.emitting = velocity.length() > (0.75 * charge_speed) and is_on_floor()
                _dust.amount_ratio = velocity.length()
        else:
                _skin.set_falling()
                velocity += get_gravity() * air_speed * delta
 
-       # now actually move!
-       var velocity_length := velocity.length()
+       var prev_velocity := velocity
        move_and_slide()
-
+       
        # handle collisions 
        for i in get_slide_collision_count():
                var c := get_slide_collision(i)
                if c.get_collider() is RigidBody3D:
                        var col: RigidBody3D = c.get_collider()
-                       col.apply_central_impulse(-c.get_normal() * velocity_length * push_force)
+                       col.apply_central_impulse(-c.get_normal() * prev_velocity.length() * push_force)