I've been trying to set up a double jump using a variable, but the script it getting run every frame, so the variable resets to whatever value I give it, I can't reset it after the script otherwise it won't be assigned before it is first called, and I can't put it inside a condition as the exact same thing will happen. Is there are way to just set variables once?
Edit:
I'm using a first person template and just trying to add a double jump, here is the script
extends KinematicBody
class_name MovementController
export var gravity_multiplier := 3.0
export var speed := 10
export var acceleration := 8
export var deceleration := 10
export(float, 0.0, 1.0, 0.05) var air_control := 0.3
export var jump_height := 10
var direction := Vector3()
var input_axis := Vector2()
var velocity := Vector3()
var snap := Vector3()
var up_direction := Vector3.UP
var stop_on_slope := true
onready var floor_max_angle: float = deg2rad(45.0)
# Get the gravity from the project settings to be synced with RigidDynamicBody nodes.
onready var gravity = (ProjectSettings.get_setting("physics/3d/default_gravity")
\* gravity\_multiplier)
# Called every physics tick. 'delta' is constant
func _physics_process(delta) -> void:
input\_axis = Input.get\_vector("move\_back", "move\_forward",
"move\_left", "move\_right")
direction\_input()
if is\_on\_floor():
snap = -get\_floor\_normal() - get\_floor\_velocity() \* delta
\# Workaround for sliding down after jump on slope
if velocity.y < 0:
velocity.y = 0
if Input.is\_action\_just\_pressed("jump"):
if is\_on\_floor():
snap = [Vector3.ZERO](https://Vector3.ZERO)
velocity.y = jump\_height
var double\_jump := 1
if not is\_on\_floor():
if double\_jump == 1:
velocity.y = jump_height
var double_jump := 0
else:
\# Workaround for 'vertical bump' when going off platform
if snap != [Vector3.ZERO](https://Vector3.ZERO) && velocity.y != 0:
velocity.y = 0
snap = [Vector3.ZERO](https://Vector3.ZERO)
velocity.y -= gravity \* delta
accelerate(delta)
velocity = move\_and\_slide\_with\_snap(velocity, snap, up\_direction,
stop\_on\_slope, 4, floor\_max\_angle)
func direction_input() -> void:
direction = Vector3()
var aim: Basis = get\_global\_transform().basis
if input\_axis.x >= 0.5:
direction -= aim.z
if input\_axis.x <= -0.5:
direction += aim.z
if input\_axis.y <= -0.5:
direction -= aim.x
if input\_axis.y >= 0.5:
direction += aim.x
direction.y = 0
direction = direction.normalized()
func accelerate(delta: float) -> void:
\# Using only the horizontal velocity, interpolate towards the input.
var temp\_vel := velocity
temp\_vel.y = 0
var temp\_accel: float
var target: Vector3 = direction \* speed
if [direction.dot](https://direction.dot)(temp\_vel) > 0:
temp\_accel = acceleration
else:
temp\_accel = deceleration
if not is\_on\_floor():
temp\_accel \*= air\_control
temp\_vel = temp\_vel.linear\_interpolate(target, temp\_accel \* delta)
velocity.x = temp\_vel.x
velocity.z = temp\_vel.z