Description
Godot version:
V3.2.stable.official
OS/device including version:
Pop!_OS 19.10
Issue description:
When a 3D KinematicBody is being moved by a move_and_slide_with_snap function and sits on top of a vertical moving platform the behaviour is inaccurate: when moving upwards the mesh enters the moving platform and when moving downwards the mesh floats slightly above it.
Steps to reproduce:
3D Space:
Create a KinematicBody for the player, add as a child a MeshRenderer (CubeMesh) and a CollisionShape (BoxShape); set all margins to 0.001. Write a move_and_slide_with_snap script and attach to it.
For the moving platform, create another kinematic body with a MeshRenderer (CubeMesh) and a CollisionShape (BoxShape); again, set all margins to 0.001. As a child add an AnimationPlayer, create a new animation and animate it's translation property up and down (Y axis) with the desired speed, duration and distances. Set the ProcessMode to Physics.
Also add a Camera and adjust it so you can see the scene.
Player script:
extends KinematicBody
export var move_speed = 750
export var gravity = 3000
export var jump_force = 1300
export var max_fall_speed = 3000
var y_velo = 0
var snap_normal = Vector3.DOWN
func movement(delta):
var move_vec = Vector3()
if Input.is_action_pressed("move_left"):
move_vec.x -= 1
if Input.is_action_pressed("move_right"):
move_vec.x += 1
move_vec *= move_speed
move_vec.y = y_velo
move_and_slide_with_snap(move_vec * delta, snap_normal, Vector3.UP)
var grounded = is_on_floor()
y_velo -= gravity * delta
if grounded:
if Input.is_action_pressed("jump"):
set_snap_normal(Vector3(0,0,0))
y_velo = jump_force
if y_velo <= 0:
set_snap_normal(Vector3.DOWN)
func set_snap_normal(new_snap_normal):
snap_normal = new_snap_normal
func _physics_process(delta):
movement(delta)
Minimal reproduction project:
moving_platform.zip
Activity