Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | AlbeyAmakiir |
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
else:
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))