0 votes

I am in the process of updating a v2 project to v3 to help assist developers in developing their own 3D projects. While some components I have ported over work without failure, I am encountering some event-driven issues, namely with player movement. This extends from the project in question.

In the code example below (taken from the project's player.gd script), I have a player pawn that is granted free movement, and the ability to jump. However, when I do jump (while holding down a movement key) and land (throwing isonfloor()), the player can't move in any direction. Once I lift all pressed keys, I can resume moving.

The code that handles jumping and motion is posted below:

    if motion != null: #TODO length() function doesn't exist here, find replacement (not null check working for now)
    while is_on_floor() && attempts: #TODO Invalid Call nonexistent function is_colliding in base 'KinematicBody'
        var n = get_collision_normal();

        if (rad2deg(acos(n.dot(Vector3(0,1,0))))< MAX_SLOPE_ANGLE):
            on_floor = true;

        motion=n.slide(motion);
        velocity=n.slide(velocity);

        if original_vel.dot(velocity) > 0:
            motion=move_and_collide(motion);
            if motion.length() < 0.001:
                break;

        attempts-=1;

if on_floor and Input.is_key_pressed(KEY_SPACE):
    velocity.y = jump_speed*gravity_factor;
    on_floor = false;

I'm not really sure what the cause could be. In discussions on Discord, it was some form of bug that emerged with v3. Any insight on how to address this bug would be helpful. Thanks again.

in Engine by (63 points)

1 Answer

0 votes

You mention that the problem goes away when you lift all pressed keys. Looking at the file you linked, the variable is_moving is true when a key is pressed. So I don't know if the bug is in the code you listed above but rather inside one of the code blocks reached by is_moving.

Also I had a similar-ish problem in v3 and v3.0.2 where:

vel = move_and_slide(vel,Vector3(0,1,0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE)

worked in v3 but not v3.0.2 (the character wouldn't move). It was fixed by adding an extra variable to the function call:

vel = move_and_slide(vel,Vector3(0,1,0), true, 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))

I don't know if it's related but it took me a while to find and so here it is just in case.

by (204 points)
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.