I'm a complete beginner and i don't exactly know what's happening but someone on reddit said the reason why my jump animation doesn't play when i have is_action_just_pressed is because the jump animation is being overridden by the movement.
how exactly do i fix that?
my current code is:
extends KinematicBody
export(NodePath) var animationtree
export var speed: = 7.0
export var jump_strength: = 15.0
export var gravity: = 50.0
var _velocity: = Vector3.ZERO
var _snap_vector: = Vector3.DOWN
var has_double_jumped = false
onready var _anim_tree = get_node(animationtree)
onready var _spring_arm: SpringArm = $SpringArm
onready var _model: Spatial = $Rabbit2
func _physics_process(delta: float) -> void:
var move_direction: = Vector3.ZERO
move_direction.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
move_direction.z = Input.get_action_strength("move_back") - Input.get_action_strength("move_forward")
move_direction = move_direction.rotated(Vector3.UP, _spring_arm.rotation.y).normalized()
_velocity.x = move_direction.x * speed
_velocity.z = move_direction.z * speed
_velocity.y -= gravity * delta
var just_landed: = is_on_floor() and _snap_vector == Vector3.ZERO
var is_jumping: = is_on_floor() and Input.is_action_just_pressed("jump")
if is_jumping:
_velocity.y = jump_strength
_snap_vector = Vector3.ZERO
elif just_landed:
_snap_vector = Vector3.DOWN
has_double_jumped = false
elif !is_on_floor() and Input.is_action_just_pressed("jump") and !has_double_jumped:
_velocity.y = jump_strength
has_double_jumped = true
_velocity = move_and_slide_with_snap(_velocity, _snap_vector, Vector3.UP, true)
if _velocity.length() > 0.2:
var look_direction = Vector2(_velocity.z, _velocity.x)
_model.rotation.y = look_direction.angle()
if Input.is_action_pressed("move_forward"):
_anim_tree["parameters/playback"].travel("Run-loop")
elif Input.is_action_pressed("move_back"):
_anim_tree["parameters/playback"].travel("Run-loop")
elif Input.is_action_pressed("move_right"):
_anim_tree["parameters/playback"].travel("Run-loop")
elif Input.is_action_pressed("move_left"):
_anim_tree["parameters/playback"].travel("Run-loop")
else:
_anim_tree["parameters/playback"].travel("Idle-loop")
if Input.is_action_just_pressed("jump") and is_on_floor():
_anim_tree["parameters/playback"].travel("Jump")
elif Input.is_action_just_pressed("jump") and not is_on_floor():
_anim_tree["parameters/playback"].travel("Doublejump")
func _process(delta: float) -> void:
_spring_arm.translation = translation
if Input.is_action_just_pressed("quit"):
get_tree().quit()