0 votes

My (3D) Kinematic First-Person player character can stand on a Kinematic moving platform that is translated and rotated horizontally using an AnimationPlayer. When the character has movement from inputs (including when inputs have been released, but deceleration hasn't finished yet), the character is carried along with the moving platform. But when the character is standing still, the platform slides out from under them; they don't move horizontally with it and will fall when it goes away. I can't seem to find why this is or how to fix it?

The input/movement code is based on the FPS tutorial here: http://docs.godotengine.org/en/latest/tutorials/3d/fps_tutorial/index.html

However, the code is very similar to the code for the Kinematic Character 3D example from the templates, and that manages to move the "cubio" character on a horizontal platform without any explicit checks.

My code is below:

func process_movement(delta):
    var camera_transform = camera.get_global_transform()

    var axis_movement = Vector2()
    axis_movement.y = Input.get_action_strength("move_forward") - Input.get_action_strength("move_backward")
    axis_movement.x = Input.get_action_strength("move_strafe_right") - Input.get_action_strength("move_strafe_left")
    axis_movement = axis_movement.normalized()

    var h_velocity = ongoing_velocity
    h_velocity.y = 0

    var target_h_velocity = Vector3()
    var acceleration

    target_h_velocity += -camera_transform.basis.z.normalized() * axis_movement.y
    target_h_velocity += camera_transform.basis.x.normalized() * axis_movement.x
    target_h_velocity = target_h_velocity.normalized() * MAX_WALK_SPEED

    if axis_movement.length() > 0:
        acceleration = WALK_ACCELERATION
        acceleration = WALK_DECELERATION

    h_velocity = h_velocity.linear_interpolate(target_h_velocity, acceleration * delta)

    if is_on_floor():
        if Input.is_action_just_pressed("move_jump"):
            ongoing_velocity.y = JUMP_SPEED

    ongoing_velocity.y += delta * GRAVITY
    ongoing_velocity.x = h_velocity.x
    ongoing_velocity.z = h_velocity.z

    ongoing_velocity = move_and_slide(ongoing_velocity, Vector3(0, 1, 0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))
in Engine by (22 points)

1 Answer

0 votes

In the line: move_and_slide(ongoing_velocity, Vector3(0, 1, 0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE)), stop_on_slope has been set to a non-zero (true) value. The FPS tutorial here includes this mistake, which is probably why your code has this. This supposedly only matters for slopes, but it also seems to matter for moving platforms. From the docs:

If the body is standing on a slope and the horizontal speed (relative to the floor's speed) goes below slopestopmin_velocity, the body will stop completely.

Setting the value to false made it work.

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