0 votes

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

func _physics_process(delta: float) -> void:
    var horizontal_movement = (
        - 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:
    elif is_falling:
    elif is_idling:
    elif is_moving:

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?

Godot version v3.3.stable.official
in Engine by (14 points)

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.

1 Answer

0 votes

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.

by (5,216 points)

I think there was override between walk, idle and jump animation. I fixed it by adding isonfloor() in isidling and ismoving. 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?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.