On Scene start my character plays jumping animation HELP PLZ

Godot Version

4.3

Question

When ever i start my scene my character will jump and play the animations.

Video showing the issue
(https://imgur.com/a/jAel8tP)

That animation doesn’t have autoplay on load toggled, right? :laughing:
Anyway, just so we know you don’t have a _ready() function on that script?

sorry i forgot to add the top part and i do have a _ready func

and none of the jump animations are looped

apply_jump_velocity()
Where do you call it from? An animation? Another script? I m a bit sleepy, so sorry if it’s an obvious question.

im new to this and i watched a youtube video for this and the apply_jump_velocity() is pulled from animation player. if i comment it out i dont jump but i still play animations and if i press space i jump but only my idle animation plays

image_2024-09-22_130401746

The function is called from the animation Jump_Start. Can you show me a little bit more to the right of that picture including the inspector?

I am using a animation tree if that makes a difference as well.

I’m looking at the usual suspects. Seems clean. Let’s see the tree then.




Ok your player starts in the focused state, so let’s focus there. So inside FocusedLocomotionStateMachines from start it goes into the “FocusedLocomotion” node. What type of node is it and if it’s a state machine, how does it look?

i start in unfocused state and the unfocused locomotion is a blendspace 1d

You switch at _ready(), right?

yes its a seperate func thats put into _ready

image_2024-09-22_150034748

the var is originally unfocused

regardless I’m willing to bet focused is a blendspace 1d too. Anyway another thing I forgot to check is your “RESET” animation. Is apply_jump_velocity() on it too?

FOCUSED is a blendspace 2d and im sorry im not sure what you mean by “RESET” animation

Look for it on the animation list.

I changed how how code is shown to make easier for u

extends CharacterBody3D

class_name Player

enum MovementMode {
	FOCUSED,
	UNFOCUSED
}

@onready var rig: Node3D = $Rig
@onready var spring_arm: SpringArm3D = $SpringArm3D
@onready var animation_tree: AnimationTree = $AnimationTree



var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")

var input: Vector2
var current_velocity: Vector2
var current_state_playback_path 
var jump_queued = false
var falling = false
var is_dodging 


@export var move_speed = 15
@export var acceleration = 15
@export var locomotion_animation_transition_speed = 0.15
@export var jump_force = 150
@export var direction_change_factor = 5
@export var dodge_velocity = 25
@export var dodge_back_velocity = 15
@export var movement_mode: MovementMode = MovementMode.UNFOCUSED
@export var focused_locomotion_state_playback_path: String
@export var unfocused_locomotion_state_playback_path: String


func _ready():
	switch_movement_mode()

func switch_movement_mode():
	var transition = "Focused" if  movement_mode == MovementMode.FOCUSED else "Unfocused"
	current_state_playback_path = focused_locomotion_state_playback_path if movement_mode == MovementMode.FOCUSED else unfocused_locomotion_state_playback_path
	animation_tree.set("parameters/Transition/transition_request", transition)

func _process(delta):
	var velocityDelta = (input - current_velocity)
	if velocityDelta.length() > locomotion_animation_transition_speed:
		velocityDelta = velocityDelta.normalized() * locomotion_animation_transition_speed


	current_velocity += velocityDelta
	var animation_velocity = current_velocity
	animation_velocity.y *= -1

	if movement_mode == MovementMode.UNFOCUSED:
		var velocity_value = maxf(absf(animation_velocity.x), absf(animation_velocity.y))
		animation_tree.set("parameters/UnfocusedLocomotionStateMation/UnfocusedLocomotion/blend_position", velocity_value)
	else:
		animation_tree.set("parameters/FocusedLocomotionStateMachine/FocusedLocomotion/blend_position", animation_velocity)

func _physics_process(delta):
	move_and_slide()

	get_input(delta)

	handle_rotation(delta)
	handle_jumping()



func handle_jumping():
	velocity.y -= gravity
	if not is_on_floor():
		jump_queued = false
		if not falling:
			falling = true
			var playback = animation_tree.get(current_state_playback_path) as AnimationNodeStateMachinePlayback
			playback.travel("Jump_Idle")
	elif  falling:
		falling = false
		var playback = animation_tree.get(current_state_playback_path) as AnimationNodeStateMachinePlayback
		playback.travel("Jump_Land")
	if jump_queued:
		velocity.y = jump_force 
		jump_queued = false
		falling = true


func handle_rotation(delta):
	
	if is_dodging:
		return
	
	if movement_mode == MovementMode.UNFOCUSED && velocity.length() > 0.01 && is_on_floor():
		rig.rotation.y = lerp_angle(rig.rotation.y, -atan2(velocity.x, -velocity.z), delta * direction_change_factor)
	elif velocity.length() > 0.01 && movement_mode == MovementMode.FOCUSED:
		rig.rotation.y = lerp_angle(rig.rotation.y, spring_arm.rotation.y, delta * direction_change_factor)

func get_input(delta):
	if is_dodging:
		return
	var vy = velocity.y
	velocity.y = 0
	input = Input.get_vector("Left", "Right", "Forward", "Backwards")
	var dir = Vector3(input.x, 0, input.y).rotated(Vector3.UP, spring_arm.rotation.y)
	velocity = lerp(velocity, move_speed * dir, delta * acceleration)
	velocity.y = vy

func _input(event):
	if Input.is_action_just_pressed("Switch_Focus"):
		movement_mode = MovementMode.FOCUSED if movement_mode == MovementMode.UNFOCUSED else MovementMode.UNFOCUSED
		switch_movement_mode()

	if is_on_floor() and Input.is_action_just_pressed("Jump"):
		begin_jump()

	if Input.is_action_just_pressed("Dodge"):
		var movement_input = Input.get_vector("Left", "Right", "Forward", "Backwards")
		dodge(movement_input)

func begin_jump():
	var playback = animation_tree.get(current_state_playback_path)
	playback.travel("Jump_Start")

func apply_jump_velocity():
	print_debug("apply_jump_velocity")
	jump_queued = true

func dodge(dir: Vector2):
	is_dodging = true
	var playback = animation_tree.get(current_state_playback_path)
	if movement_mode == MovementMode.UNFOCUSED:
		if dir == Vector2.ZERO:
			velocity = rig.transform.basis.z * dodge_back_velocity
			playback.travel("Dodge_Backward")
		else:
			velocity = -rig.transform.basis.z * dodge_velocity
			playback.travel("Dodge_Forward")

	elif movement_mode == MovementMode.FOCUSED:
		if dir == Vector2.ZERO:
			velocity = rig.transform.basis.z * dodge_back_velocity
			playback.travel("Dodge_Backward")
		elif  dir == Vector2.LEFT:
			velocity = -rig.transform.basis.x * dodge_velocity
			playback.travel("Dodge_Left")
		elif  dir == Vector2.RIGHT:
			velocity = rig.transform.basis.x * dodge_velocity
			playback.travel("Dodge_Right")
		elif  dir == Vector2.DOWN:
			velocity = rig.transform.basis.z * dodge_back_velocity
			playback.travel("Dodge_Backward")
		elif  dir == Vector2.UP:
			velocity = -rig.transform.basis.z * dodge_velocity
			playback.travel("Dodge_Forward")
		


func finish_dodge():
	is_dodging = false
	velocity = Vector3.ZERO

i dont have a reset but my “Idle” animation doesnt have apply_jump_velocity()