I am using CharacterController.Move to move the player, and I make the player child of the moving platform to move with it, but it is not working, the player doesn’t move with the platform.
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Platform")
{
transform.parent = other.transform.parent;
}
}
private void OnTriggerExit(Collider other)
{
if (other.tag == "Platform")
{
transform.parent = null;
}
}
This up code works well, the player change and takes the platform as parent. But the player falls, and not moving with the platform.
if (Control.isGrounded)
{
MoveDir = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
MoveDir *= Speed;
JumpCount = 0;
}
else
{
MoveDir = new Vector3(Input.GetAxis("Horizontal") * Speed, MoveDir.y, Input.GetAxis("Vertical") * Speed);
}
if (Input.GetButtonDown("Jump") && JumpCount < TotalJumps)
{
JumpCount++;
MoveDir.y = JumpSpeed;
}
MoveDir.y -= Gravity * Time.deltaTime;
if (ActivateMove)
{
if (MoveDir != Vector3.zero)
{
Control.Move(MoveDir * Time.deltaTime);
}
}
This is the player moving script. I put a boolean “ActivateMove” to desactivate the movement and check, if is desactivate the player moves with the platorm and it works. But I can’t desactive the movement when the player is in the moving platform becouse I want to move it in the platform too.
Thank you.