Need help with variable scope and Vector3s

That’s the best title I could come up with :sob:
My issue is that vault_vel doesn’t get constantly updated to itself times dir, which is a normalized vector pointing in the direction the players want to go.
Since vault_vel is trying to move toward Vector3.Zero, if dir is 0,0,0 vault_vel is immediately canceled. But this isn’t the behavior I want. If dir is 0,0,0 I want vault_vel to be 0,0,0 but if dir changes to 1,0,0 I want vault_vel to still have a value to be multiplied by.

Since I can tell I didnt explain this well, if you have question ask away.

Cutoff Code:

	#Jump or vault
	if jump_buff.time_left > 0:
		#Vaulting
		if vault_cast.is_colliding():
			if Vector3.UP.dot(vault_cast.get_collision_normal(0)) > 0:
				#Update timers
				jump_buff = get_tree().create_timer(0)
				jump_debounce = get_tree().create_timer(ascend_cool)

				#Local vars
				var vault_diff := vault_cast.get_collision_point(0) - global_position
				var height:float = vault_power + vault_diff.y * vault_power_growth

				#Apply impulses
				base_vel.y = height
				base_vel.x *= vault_speed_multi
				base_vel.z *= vault_speed_multi

				#Stacking?
				if vault_boost_stack:
					vault_vel += vault_boost * dir
				else:
					vault_vel = vault_boost * dir

				#Handle Conllisions
				if dir.dot(Vector3(vault_diff.x, 0 , vault_diff.z).normalized()) > 0:
					anim_plr.play("Vault")
					collision.disabled = true
					await get_tree().create_timer(vault_clip_time).timeout
					collision.disabled = false
				#Return to prevent jump
				return

How is vault_boost defined? Could you detect if the dir length is less than one? Would it be better to use a forward vector with -basis.z?

1 Like
@export var vault_boost:float = 4

Idk, it used to work a while ago without having to detect whether or not its higher than 0 or whatever you said.
And idk what you mean, would it be better to use a forward vector.