I have what I believe is a standard FPS controller where I call HandleMovement() in every update (not FixedUpdate). The actual movement happens with characterController.Move(moveDirection * Time.deltaTime);. If I comment this out, my character moves with a platform. Of course this also means I literally cannot move or even rotate the camera. With that line of code not commented out, the player doesn’t move with the platform at all.
Here’s the full code in case it’s relevant:
void HandleMovement() {
Vector3 forward = transform.TransformDirection(Vector3.forward);
Vector3 right = transform.TransformDirection(Vector3.right);
bool isRunning = Input.GetKey(KeyCode.LeftShift);
float curSpeedX = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Vertical") : 0;
float curSpeedY = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Horizontal") : 0;
float movementDirectionY = moveDirection.y;
moveDirection = (forward * curSpeedX) + (right * curSpeedY);
if (Input.GetButton("Jump") && canMove && characterController.isGrounded) {
moveDirection.y = jumpSpeed;
} else {
moveDirection.y = movementDirectionY;
}
if (!characterController.isGrounded) {
moveDirection.y -= gravity * Time.deltaTime;
}
// characterController.Move(moveDirection * Time.deltaTime);
if (canMove) {
rotationX += -Input.GetAxis("Mouse Y") * lookSpeed;
rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * lookSpeed, 0);
}
}
The platform moves very simply and makes the player a child object like so:
private void FixedUpdate() {
if (active) {
Vector3 newPos = transform.position + move;
rb.MovePosition(newPos);
}
}
private void OnTriggerEnter(Collider other) {
if (other.tag == "Player") {
other.transform.SetParent(transform);
active = true;
}
}
I feel like I must be missing something pretty obvious as to why this is an issue. I’m on Unity 2020.1.16f1.