Advertisement
Guest User

WIP dash issues

a guest
Jun 18th, 2025
36
0
5 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @export_category("ground speed variables")
  2. @export var base_speed : float = 5.0
  3. @export var base_speed_mod : float = 1.0
  4. @export var run_speed_mod : float = 1.4
  5. @export var crouch_speed_mod : float = 0.5
  6. @export var dash_distance : float = 500
  7. @export var dash_duration : float = 0.5
  8. @export var ramp_speed :float = 4.0
  9. @export var rotation_speed : float = 20.0
  10.  
  11. @export_category("jump variables")
  12. @export var total_air_actions : int = 2
  13. var current_air_actions : int = total_air_actions - 1
  14. @export var air_control_mod : float = 0.25
  15. @export var fast_fall : float = 0.6
  16. @export var base_jump_height : float = 3.5
  17. @export var jump_height_mod : float = 1.0
  18. @export var jump_time_to_peak : float = 0.4
  19. @export var jump_time_to_descent : float = 0.3
  20. @export var jump_distance_mod : float = 1.0
  21.  
  22. var total_speed : float = base_speed * base_speed_mod
  23. var speed : float = total_speed / (jump_time_to_peak + jump_time_to_descent)
  24.  
  25. @onready var dash_velocity : float = dash_distance / dash_duration
  26. @onready var jump_velocity : float = (2 * base_jump_height) / jump_time_to_peak
  27. @onready var jump_gravity : float = (-2 * base_jump_height) / pow(jump_time_to_peak, 2)
  28. @onready var fall_gravity : float = (-2 * base_jump_height) / pow(jump_time_to_descent, 2)
  29.  
  30. var Ls_input : Vector2
  31.  
  32.  
  33. func _physics_process(delta : float) ->
  34.     #WIP states
  35.     states_logic(delta)
  36.     #grounded movement and jumping
  37.     jump_logic(delta)
  38.     movement_logic(delta)
  39.     #model lookat for targeting
  40.     rotate_look_at_point(delta)
  41.    
  42.     move_and_slide()
  43.  
  44.  
  45. func movement_logic(delta : float) -> void:
  46.     Ls_input = Input.get_vector("LsLeft", "LsRight", "LsUp", "LsDown").normalized().rotated(-camera.global_rotation.y)
  47.     var velocity2D := Vector2(velocity.x, velocity.z)
  48.     var move_speed : float
  49.     var run_speed : float = speed * run_speed_mod
  50.     var crouch_speed : float = speed * crouch_speed_mod
  51.  
  52.  
  53. [...] # 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
  54.  
  55.  
  56.     if Ls_input != Vector2.ZERO:
  57.         if velocity.y > 0.0:
  58.             velocity2D += Ls_input * move_speed * delta * ramp_speed * air_control_mod
  59.             velocity2D = velocity2D.limit_length(move_speed * jump_distance_mod)
  60.             velocity.x = velocity2D.x * jump_distance_mod
  61.             velocity.z = velocity2D.y * jump_distance_mod
  62.         else:
  63.             velocity2D += Ls_input * move_speed * delta * ramp_speed
  64.             velocity2D = velocity2D.limit_length(move_speed)
  65.             velocity.x = velocity2D.x
  66.             velocity.z = velocity2D.y
  67.     else:
  68.         if !is_on_floor(): #hopefully preserve player momentum for jumps
  69.             velocity2D += Ls_input * move_speed * delta * ramp_speed
  70.             velocity2D = velocity2D.limit_length(move_speed)
  71.             velocity.x = velocity2D.x
  72.             velocity.z = velocity2D.y
  73.         else:
  74.             velocity2D = velocity2D.move_toward(Vector2.ZERO, move_speed * delta * ramp_speed)
  75.             velocity.x = velocity2D.x
  76.             velocity.z = velocity2D.y
  77.    
  78.  
  79.     #WIP air dash - needs fussing with, currently just teleports you rather than ramping between current speed and the dash speed and back
  80.     if Input.is_action_just_pressed("FaceRight") and current_air_actions >= 1:
  81.         velocity.x = Ls_input.x * dash_velocity
  82.         velocity.y = clampf(jump_gravity, 1, jump_gravity * 0.2)
  83.         velocity.z = Ls_input.y * dash_velocity
  84.  
  85.         current_air_actions -= 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement