0 votes

Hi i have problem because when my player character jump on platform while moving my character falling (image below)

Here is moving script

    sprint = false;
    iswalk = false;

    Vector3 direction = new Vector3();
    direction.x = 0;
    direction.z = 0;

    var aim = camera.GlobalTransform.basis;

    if (Input.IsActionPressed("ui_left"))
    {
        direction -= aim.x;

        //Rotation
        GetNode<Spatial>("Armature").Rotation = new Vector3(0f, Mathf.LerpAngle(GetNode<Spatial>("Armature").Rotation.y, Mathf.Atan2(velocity.x, velocity.z), delta * 7f), 0f);

        //Animation
        iswalk = true;
    }

    if (Input.IsActionPressed("ui_right"))
    {
        direction += aim.x;

        //Rotation
        GetNode<Spatial>("Armature").Rotation = new Vector3(0f, Mathf.LerpAngle(GetNode<Spatial>("Armature").Rotation.y, Mathf.Atan2(velocity.x, velocity.z), delta * 7f), 0f);

        //Animation
        iswalk = true;
    }

    if (Input.IsActionPressed("ui_up"))
    {
        direction -= aim.z;

        //Rotation
        GetNode<Spatial>("Armature").Rotation = new Vector3(0f, Mathf.LerpAngle(GetNode<Spatial>("Armature").Rotation.y, Mathf.Atan2(velocity.x, velocity.z), delta * 7f), 0f);

        //Animation
        iswalk = true;
    }

    if (Input.IsActionPressed("ui_down"))
    {
        direction += aim.z;

        //Rotation
        GetNode<Spatial>("Armature").Rotation = new Vector3(0f, Mathf.LerpAngle(GetNode<Spatial>("Armature").Rotation.y, Mathf.Atan2(velocity.x, velocity.z), delta * 7f), 0f);

        //Animation
        iswalk = true;
    }

    if (Input.IsActionPressed("sprint"))
    {
        sprint = true;
    }

    //Animation

    if (iswalk)
    {
        if (sprint)
        {
            move_animation = animator.SetValue(delta, ref move_animation, 1f);
            animationTree.Set("parameters/walk/blend_amount", move_animation);
        }
        else
        {
            move_animation = animator.SetValue(delta, ref move_animation, -1f);
            animationTree.Set("parameters/walk/blend_amount", move_animation);
        }
    }
    else
    {
        move_animation = animator.SetValue(delta, ref move_animation, 0f);
        animationTree.Set("parameters/walk/blend_amount", move_animation);
    }

    // End Animation

    //Jump Animation

    if (Input.IsActionJustPressed("jump") && IsOnFloor())
    {
        velocity.y += 3f;
    }

    if (!IsOnFloor())
    {
        jump_animation = animator.SetValue(delta, ref jump_animation, 1f);
        animationTree.Set("parameters/jump/blend_amount", jump_animation);
    }
    else
    {

        jump_animation = animator.SetValue(delta, ref jump_animation, 0f);
        animationTree.Set("parameters/jump/blend_amount", jump_animation);
    }

    //End Animation

    direction = direction.Normalized();

    velocity.y -= gravity * delta;

    var temp_velocity = velocity;
    temp_velocity.y = 0;

    Vector3 target;

    if (sprint)
    {
        if (IsOnFloor())
        {
            target = direction * 6f;
        }
        else
        {
            target = direction * 4f;
        }
    }
    else
    {
        target = direction * 2f;
    }

    int acceleration = 0;

    if (direction.Dot(temp_velocity) > 0)
    {
        acceleration = 2;
    }
    else
    {
        acceleration = 6;
    }

    temp_velocity = velocity.LinearInterpolate(target, 4 * delta);

    velocity.x = temp_velocity.x;
    velocity.z = temp_velocity.z;

    velocity = MoveAndSlide(velocity + GetFloorVelocity(), Vector3.Up);

Here is my scene tree
image

Here is how player react while platform moving
image

Godot version 3.3.2
in Engine by (74 points)
edited by

Please log in or register to answer this question.

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.