Which approach would be the right one to implement a conveyor belt?
If the GameObject is on the default layer, e.g. the running animation did not play properly. With Moving Platform - Layer there are rotation problems.
If the GameObject is on the default layer, e.g. the running animation did not play properly. With Moving Platform - Layer there are rotation problems.
Code:
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Utility;
using UnityEngine;
public class ConveyorBelt : MonoBehaviour
{
public Transform endpoint;
public float speed = 0.1f;
public LayerMask m_LayerMask = ~0;
private void OnTriggerStay(Collider other)
{
if (!MathUtility.InLayerMask(other.gameObject.layer, m_LayerMask))
{
return;
}
var locomotion = other.GetComponentInParent<UltimateCharacterLocomotion>();
if (locomotion)
{
if (Vector3.Distance(locomotion.transform.position, endpoint.position) > 0.2f)
{
var position = Vector3.Lerp(locomotion.transform.position, endpoint.position, speed * Time.deltaTime);
locomotion.SetPosition(position, true);
}
}
}
}