Godot Version
4.2.2
Question
currently my dashing is supposed to change the horizontal velocity
(hor_movement in code) it does do it but its really buggy and and stutters it might only be the camera bcs its a 3rd person one but i fixed it by making it not hit the player collision
i also want the controlled velocity to affect the uncontrolled one
thanks in advance :3
extends CharacterBody3D
#velocity upadted
var hor_movement : Vector3
var ver_movement : Vector3
var dash_movement : Vector3
#horizontal updated
var controlled_hmovement : Vector3
var uncontrolled_hmovement : Vector3
#player stats variables unused for now
var health : int = 10
var fuel : float = 1.00
#jump variables
var time_to_peak : float = 0.35
var j_height : float = 2.75
var descent : float = 0.3
var jumpvel : float = (2.0 * j_height) / time_to_peak
var grav : float = (-2.0 * j_height) / (descent * descent)
var jumpgrav : float = (-2.0 * j_height) / (time_to_peak * time_to_peak)
#move variables
var maxwalk : float = 8
var accel_walk : float = 1
var decel_walk : float = 0.8
#aerial variabels
var aerial_decel : float = 0.3
#dash variables
var dash_vel : float = 25
var is_dash : bool = false
@onready var dash_time : Timer = $dash_time
#cam variables
var sens : float = 0.003
@onready var pivot : Node3D = $neck
@onready var giraffe_pivot : SpringArm3D = $neck/giraffe_pivot
func get_decel():
return decel_walk if is_on_floor() else aerial_decel
func getgrav():
if ver_movement.y > 0:
return jumpgrav
else:
return grav
# Called when the node enters the scene tree for the first time.
func _ready():
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _unhandled_input(event):
if event is InputEventMouseMotion:
pivot.rotate_y(-event.relative.x * sens)
$neck/giraffe_pivot.rotate_x(-event.relative.y * sens)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
#walk movement
var input_dir = Input.get_vector("a","d","w","s")
var move_dir : Vector3 = (pivot.transform.basis * Vector3(input_dir.x,0,input_dir.y)).normalized()
if move_dir:
controlled_hmovement = controlled_hmovement.move_toward(maxwalk * move_dir,accel_walk)
else:
controlled_hmovement = controlled_hmovement.move_toward(Vector3.ZERO,get_decel())
#gravity
if !is_on_floor():
ver_movement.y += getgrav() * delta
else:
ver_movement.y = 0
#jump
if Input.is_action_just_pressed("space") and is_on_floor():
ver_movement.y += jumpvel
#dash stuff
if Input.is_action_just_pressed("shift"):
dash_time.start()
if dash_time.is_stopped() == false:
dash_movement = dash_vel * -pivot.global_basis.z
is_dash = true
else:
dash_movement = Vector3.ZERO
is_dash = false
if is_dash == true and Input.is_action_just_pressed("space") and is_on_floor():
dash_time.stop()
uncontrolled_hmovement += dash_movement
dash_movement = Vector3.ZERO
uncontrolled_hmovement = uncontrolled_hmovement.move_toward(Vector3.ZERO,get_decel())
hor_movement = controlled_hmovement + uncontrolled_hmovement
velocity = hor_movement + ver_movement + dash_movement
move_and_slide()