i want my character to continue to have the same speed as he started when he jumps.
now whenever i stop holding shift(to do running) the character returns to normal speed.
this is probably easy to do, but i cant figure it out.
heres the basic movement code
func _physics_process(delta):
process_movement_inputs()
process_vertical_movement(delta)
process_movement(delta)
func process_movement_inputs():
# Get the input directions
dir = Vector3.ZERO
if Input.is_action_pressed("forward"):
dir -= global_transform.basis.z
if Input.is_action_pressed("backward"):
dir += global_transform.basis.z
if Input.is_action_pressed("right"):
dir += global_transform.basis.x
if Input.is_action_pressed("left"):
dir -= global_transform.basis.x
# Normalizing the input directions
dir = dir.normalized()
func process_vertical_movement(delta):
# When on floor - Reset vertical movement & completely disable wallrunning
if is_on_floor():
myvelocity.y = -0.01
# Apply gravity
else:
myvelocity.y += GRAVITY * delta
#check landing
if !prevGrounded and is_on_floor():
isjumping = false
footsteps.playLandSound()
# Jump
if Input.is_action_just_pressed("jump") and is_on_floor() :
isjumping = true
if isrunning :
myvelocity.y = RUN_JUMP_SPEED
else:
myvelocity.y = JUMP_SPEED
#snap = Vector3.ZERO
footsteps.playJumpSound()
#else:
#
# snap = Vector3.DOWN
prevGrounded = is_on_floor()
func process_movement(delta):
# Set speed and target velocity
if Input.is_action_pressed("sprint"):
wantedspeed = SPRINT_SPEED
isrunning = true
else:
wantedspeed = SPEED
isrunning = false
var target_vel = dir * wantedspeed
# Smooth out the player's movement
var accel = ACCEL if is_on_floor() else AIR_ACCEL
current_vel = current_vel.lerp(target_vel, accel * delta)
# Finalize velocity and move the player
myvelocity.x = current_vel.x
myvelocity.z = current_vel.z
velocity = myvelocity
#apply rigidbodyforces ?>
move_and_slide()
myvelocity = velocity
# Apply Effects
process_movement_effects( delta)
ApplyBob(delta)
playfootsounds()
#process_UI(delta)
process_Input(delta)
func process_movement_effects( delta):
# and velocity_info.length() > 3.0
# Sprint Effect
var calculatefloorvelocity = Vector3(velocity.x,0,velocity.z)
var velSize = calculatefloorvelocity.length()
var flatVelocity = velSize
if flatVelocity > SPEED + 1 :
#weapon_camera.fov = lerp(weapon_camera.fov, weaponRunFOV, 10 * delta)
camera.fov = lerp(camera.fov, 80, 10 * delta)
else:
#weapon_camera.fov = lerp(weapon_camera.fov, weaponFOV, 10 * delta)
camera.fov = lerp(camera.fov, 70, 10 * delta)