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)

If you let go of shift, of course that will happen. That's how it's set up. Does it stay at the same speed if you hold on to shift and also press jump?

@fire7side said: If you let go of shift, of course that will happen. That's how it's set up. Does it stay at the same speed if you hold on to shift and also press jump?

yes it stays the same when holding shift. i know that. i need to add some kind of condition to keep the speed the character was at when he started jumping and keep that speed until he lands

On line 82, try putting a comment right before the "else"

@fire7side said: On line 82, try putting a comment right before the "else"

sorry i dont understand what i should comment. "air accell" isnt the problem i think.

That's when he's in the air. The acceleration probably also includes deceleration. Anyway, just find out what it does. The jump should still handle the upward motion and gravity should handle the downward motion. Just comment it so you can put it back in.

no it doesnt handle deceleration

if Input.is_action_pressed("sprint"):
		wantedspeed = SPRINT_SPEED
		isrunning = true
	else:
		
		wantedspeed = SPEED
		isrunning = false
	
	
	var target_vel = dir * wantedspeed

speed is constantly calculated by the shift button input i need to determine the last known speed when starting the jump and setting it back to normal input when he landed

Is the character stopping when he lands even with the run input held down?

Does replacing

if Input.is_action_pressed("sprint"):
	wantedspeed = SPRINT_SPEED
	isrunning = true
else:
	
	wantedspeed = SPEED
	isrunning = false

with

if is_on_floor() and Input.is_action_pressed("sprint"):
	wantedspeed = SPRINT_SPEED
	isrunning = true
elif is_on_floor():
	
	wantedspeed = SPEED
	isrunning = false

do it?

@spacecloud said: Does replacing

if Input.is_action_pressed("sprint"):
	wantedspeed = SPRINT_SPEED
	isrunning = true
else:
	
	wantedspeed = SPEED
	isrunning = false

with

if is_on_floor() and Input.is_action_pressed("sprint"):
	wantedspeed = SPRINT_SPEED
	isrunning = true
elif is_on_floor():
	
	wantedspeed = SPEED
	isrunning = false

do it?

tnx! that actually works> @fire7side said:

Is the character stopping when he lands even with the run input held down?

no

8 months later