Moving Platforms
public void FixedUpdate()
{
float t = EaseInOut(Mathf.PingPong(Time.time, _moveTime), _moveTime);
Vector3 p = Vector3.Lerp(_startPosition, _targetPosition, t);
_rigidbody.MovePosition(p);
}public class OneWayPlatform : MonoBehaviour
{
public Collider platformCollider;
private void OnTriggerEnter(Collider other)
{
if (!other.CompareTag("Player"))
return;
Character character = other.GetComponent<Character>();
if (character)
character.IgnoreCollision(platformCollider);
}
private void OnTriggerExit(Collider other)
{
if (!other.CompareTag("Player"))
return;
Character character = other.GetComponent<Character>();
if (character)
character.IgnoreCollision(platformCollider, false);
}
}Last updated