Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @export_category("ground speed variables")
- @export var base_speed : float = 5.0
- @export var base_speed_mod : float = 1.0
- @export var run_speed_mod : float = 1.4
- @export var crouch_speed_mod : float = 0.5
- @export var dash_distance : float = 500
- @export var dash_duration : float = 0.5
- @export var ramp_speed :float = 4.0
- @export var rotation_speed : float = 20.0
- @export_category("jump variables")
- @export var total_air_actions : int = 2
- var current_air_actions : int = total_air_actions - 1
- @export var air_control_mod : float = 0.25
- @export var fast_fall : float = 0.6
- @export var base_jump_height : float = 3.5
- @export var jump_height_mod : float = 1.0
- @export var jump_time_to_peak : float = 0.4
- @export var jump_time_to_descent : float = 0.3
- @export var jump_distance_mod : float = 1.0
- var total_speed : float = base_speed * base_speed_mod
- var speed : float = total_speed / (jump_time_to_peak + jump_time_to_descent)
- @onready var dash_velocity : float = dash_distance / dash_duration
- @onready var jump_velocity : float = (2 * base_jump_height) / jump_time_to_peak
- @onready var jump_gravity : float = (-2 * base_jump_height) / pow(jump_time_to_peak, 2)
- @onready var fall_gravity : float = (-2 * base_jump_height) / pow(jump_time_to_descent, 2)
- var Ls_input : Vector2
- func _physics_process(delta : float) ->
- #WIP states
- states_logic(delta)
- #grounded movement and jumping
- jump_logic(delta)
- movement_logic(delta)
- #model lookat for targeting
- rotate_look_at_point(delta)
- move_and_slide()
- func movement_logic(delta : float) -> void:
- Ls_input = Input.get_vector("LsLeft", "LsRight", "LsUp", "LsDown").normalized().rotated(-camera.global_rotation.y)
- var velocity2D := Vector2(velocity.x, velocity.z)
- var move_speed : float
- var run_speed : float = speed * run_speed_mod
- var crouch_speed : float = speed * crouch_speed_mod
- [...] # some snipped basic state checks to make movespeed = runspeed or crouchspeed if you're in the relevant state, as well as jump hight/distance modifiers
- if Ls_input != Vector2.ZERO:
- if velocity.y > 0.0:
- velocity2D += Ls_input * move_speed * delta * ramp_speed * air_control_mod
- velocity2D = velocity2D.limit_length(move_speed * jump_distance_mod)
- velocity.x = velocity2D.x * jump_distance_mod
- velocity.z = velocity2D.y * jump_distance_mod
- else:
- velocity2D += Ls_input * move_speed * delta * ramp_speed
- velocity2D = velocity2D.limit_length(move_speed)
- velocity.x = velocity2D.x
- velocity.z = velocity2D.y
- else:
- if !is_on_floor(): #hopefully preserve player momentum for jumps
- velocity2D += Ls_input * move_speed * delta * ramp_speed
- velocity2D = velocity2D.limit_length(move_speed)
- velocity.x = velocity2D.x
- velocity.z = velocity2D.y
- else:
- velocity2D = velocity2D.move_toward(Vector2.ZERO, move_speed * delta * ramp_speed)
- velocity.x = velocity2D.x
- velocity.z = velocity2D.y
- #WIP air dash - needs fussing with, currently just teleports you rather than ramping between current speed and the dash speed and back
- if Input.is_action_just_pressed("FaceRight") and current_air_actions >= 1:
- velocity.x = Ls_input.x * dash_velocity
- velocity.y = clampf(jump_gravity, 1, jump_gravity * 0.2)
- velocity.z = Ls_input.y * dash_velocity
- current_air_actions -= 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement