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}
_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
# 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)
# timescale tweaking for fun effect!
if _player_speed == charge_speed:
_skin.set_timescale(2.0)
+
else:
_skin.set_timescale(1.0)
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)