Jump Animation is not working

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Quote19

Hello! I was coding my player movement + animations and found a problem that my player is not playing jump animation when jumping but the fall and other animations seems to work correctly and I check there’s no mistake in naming of animation or case sensitivity.

extends KinematicBody2D

const UP_DIRECTION := Vector2.UP
const SNAP_DIRECTION := Vector2.DOWN
const SNAP_LENGTH = 32.0
const SLOPE_THRESHOLD = deg2rad(46)

export var speed := 20
export var gravity := 3000
export var jump_strength := 800.0
var _velocity := Vector2.ZERO
var snap_vector := SNAP_DIRECTION * SNAP_LENGTH

onready var pivot: Node2D = $AnimatedSprite
onready var _start_scale: Vector2 = pivot.scale

export var maximum_jumps := 1
var jumps_made := 0 

func _ready() -> void:
	var map_limits = get_parent().get_node("Tile Layer 1").get_used_rect()
	var map_cellsize = get_parent().get_node("Tile Layer 1").cell_size
	$Camera2D.limit_left = map_limits.position.x * map_cellsize.x
	$Camera2D.limit_right = map_limits.end.x * map_cellsize.x
	$Camera2D.limit_top = map_limits.position.y * map_cellsize.y
	$Camera2D.limit_bottom = map_limits.end.y * map_cellsize.y
	pass

func _physics_process(delta: float) -> void:
	var horizontal_movement = (
		Input.get_action_strength("move_forward")
		- Input.get_action_strength("move_backward")
		)
		
	_velocity.x = horizontal_movement * speed
	_velocity.y += gravity * delta
	 #_velocity.y = move_and_slide_with_snap(_velocity, snap_vector, UP_DIRECTION, true, 4, SLOPE_THRESHOLD).y
	
	
	var is_jumping := Input.is_action_just_pressed("jump") and is_on_floor()
	var is_moving :=  not is_zero_approx(_velocity.x)
	var is_idling := is_zero_approx(_velocity.x)
	var is_falling := _velocity.y > 0.0 and not is_on_floor()
	
	if is_jumping:
		jumps_made = 1
		_velocity.y = -jump_strength
		
		
	elif is_idling:
		jumps_made = 0
		
	elif is_moving:
		jumps_made = 0
		
		
	_velocity = move_and_slide(_velocity, UP_DIRECTION, true)
	
	if not is_zero_approx(_velocity.x):
		pivot.scale.x = sign(_velocity.x) * _start_scale.x
		
	if  is_jumping:
		$AnimationPlayer.play("Jump")
	elif is_falling:
		$AnimationPlayer.play("Fall")
	elif is_idling:
		$AnimatedSprite.play("Idle")
	elif is_moving:
		$AnimatedSprite.play("Walk")

If there is no error in the code. I will post my project here to check the issue outside of the code but I don’t know how do I post my project here?

I am not sure whether its a place to ask but I am making a fan project for learning purpose and I couldn’t make animation timing same as the original game. I tried watching the gameplay frame by frame but don’t know how accurate it is also couldn’t able to calculate frames in secs by which I couldn’t put it in animationplayer accurately. Any help? The original game is Castlevania: Rondo of Blood.

Quote19 | 2022-01-22 15:55

:bust_in_silhouette: Reply From: Inces

Your mistook jumping state with jumping conditions. Your is_jumping us true when player is on floor and button is just pressed. That means jump animation plays one frame after pressing button, before velocity.y goes up. Right after this frame idle or walk is played, because they only care for velocity.x. You need to add another boolean state for being in the air- for when velocity.y is less than 0.

I think there was override between walk, idle and jump animation. I fixed it by adding is_on_floor() in is_idling and is_moving. Like this :-

var is_moving :=  not is_zero_approx(_velocity.x) and is_on_floor()
var is_idling := is_zero_approx(_velocity.x) and is_on_floor()

Thanks anyways, but there’s a problem I am trying to get smooth animation as the original game which I am copying but unable to get it smooth but I think this question is irrelevant on this website, right?

Quote19 | 2022-01-23 05:04