Movement interrupts everything else

On version 4.2.2

My running animation seems to just play all the time not just when i’m moving and interrupts every other animation any ideas on why it’s doing this

This screenshot is of a commented line of code, this tells us that the “Run” animation should never run, unless it’s an autoload.

When on the forum please paste scripts using the </> button on a new line like so, screenshots make it harder to give advice if we can’t also copy them to make changes.

```
type or paste code here
```

I know its a commented, sorry i meant to say like i had made it commented so that it wont overwrite other stuff but whenever it’s not commented it plays over everything else

func _process(delta: float) -> void:
	var input := Vector3.ZERO
	if groundpounding == false:
		if wallstick == false:
			input.x = Input.get_axis("move_right", "move_left")
			input.z = Input.get_axis("move_back", "move_forward")
			apply_central_force(twist_pivot.basis * input * currentspeed * delta)
			#$Character/AnimationPlayer.play("Run")

it will play if you aren’t ground pounding or wall sticking, how are the other animations played?

You need to find what condition would satisfy playing run but not the others? I assume running == input > 0 and is_on_floor() is a good start?

Do you have the Run animation set to loop.

I actually just got it to work like this

func _process(delta: float) -> void:
	var input := Vector3.ZERO
	if groundpounding == false:
		if wallstick == false:
			input.x = Input.get_axis("move_right", "move_left")
			input.z = Input.get_axis("move_back", "move_forward")
			apply_central_force(twist_pivot.basis * input * currentspeed * delta)
			if $RayCast3D.is_colliding():
				if isCrouching == false:
					if Input.is_action_just_pressed("move_back"): 
						$Character/AnimationPlayer.play("Run")
					elif Input.is_action_just_pressed("move_left"):
						$Character/AnimationPlayer.play("Run")
					elif Input.is_action_just_pressed("move_back"):
						$Character/AnimationPlayer.play("Run")
					elif Input.is_action_just_pressed("move_forward"):
						$Character/AnimationPlayer.play("Run")

Currently it only plays like when i tap it and if i keep movement held it doesn’t keep play only plays once then stops till i press the input again any tips on getting it to loop just when held

Mark your “Run” animation as looping

It’s telling me this “Can’t change loop mode on animation embedded in another scene.” Is it cause its imported from blender?

1 Like

If this is from a GLB/DAE/FBX you can change it in the import settings, double click the file in the filesystem, select the animation and you want loop mode “linear”

You can read more about scene imports here, though they do not go over animations.

Ok well that does make it loop but not only when im holding it, like even if i let go it still continues

Try this, I reduce the if/elif by checking the already retrieved input, then I stop the animator if the Run animation is playing and input is zero

input.x = Input.get_axis("move_right", "move_left")
input.z = Input.get_axis("move_back", "move_forward")
apply_central_force(twist_pivot.basis * input * currentspeed * delta)
if $RayCast3D.is_colliding():
	if isCrouching == false:
		var is_moving: bool = not input.is_zero_approx()
		if is_moving: 
			$Character/AnimationPlayer.play("Run")
		elif $Character/AnimationPlayer.current_animation == "Run":
			$Character/AnimationPlayer.stop() # or play "Idle" if available

You might not need to check current_animation == "Run", in most of my controllers using else is enough.

Ok that works great with the idle and everything but one thing i notice is how do i get the idle to play upon loading the scene initially as the idle only plays once i move then stop

(edit: and also if im on the ground dashing or jumping while holding the movement button it overwrites the dash or jump anim which im assuming is cause for a few frames the raycast is still colliding)

That’s the hard part. You’ve got a lot of states to go through, it might do you well to research finite state machines for your player, it’s a good way to organize such things. But the main question you need to ask is when do I play this animation or that, test often.

Running sounds like it’s on the floor, with input, not dashing. How do you transform that into a if statement?

Jumping is not on the floor, not ground pounding

Idle is none of the above.

This is how i make dashing an action

if Input.is_action_just_pressed("dash") and can_dash:
		if $RayCast3D.is_colliding():
			apply_central_impulse(Vector3.UP * 2.0)
			onground = true
			can_dash = false
			apply_central_impulse(twist_pivot.basis * input * DASH_SPEED * delta)
			timer.start()
			self.gravity_scale = 0
			isdashing = true
			$Character/AnimationPlayer.play("Dash")
			
		else:
			onground = true
			can_dash = false
			apply_central_impulse(twist_pivot.basis * input * DASH_SPEED * delta)
			timer.start()
			self.gravity_scale = 0
			isdashing = true
			$Character/AnimationPlayer.play("Dash")

And for the jumping i mean like when i try to jump off the floor while moving it like starts the jump anim but then next frame then plays the run anima again

(And ill look into state machines tomorrow)

1 Like