Advertisement
zidanKohai

Untitled

May 17th, 2025
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using KinematicCharacterController;
  2. using UnityEngine;
  3.  
  4. namespace Runtime.Platform
  5. {
  6.     public class MoveablePlatform : MonoBehaviour, IMoverController
  7.     {
  8.         public PhysicsMover Mover;
  9.  
  10.         [SerializeField] private Vector3 translationAxis = Vector3.right;
  11.         [SerializeField] private float translationPeriod = 10;
  12.         [SerializeField] private float translationSpeed = 1;
  13.         [SerializeField] private bool isAxisLocal = false;
  14.         [SerializeField] private Vector3 rotationAxis = Vector3.up;
  15.         [SerializeField] private float rotSpeed = 10;
  16.  
  17.         private Vector3 _originalPosition;
  18.  
  19.         private void Start()
  20.         {
  21.             _originalPosition = transform.position;
  22.  
  23.             var rotationAxis = isAxisLocal ? transform.TransformDirection(this.rotationAxis) : this.rotationAxis;
  24.  
  25.             Mover.MoverController = this;
  26.         }
  27.  
  28.         public void UpdateMovement(out Vector3 goalPosition, out Quaternion goalRotation, float deltaTime)
  29.         {
  30.             goalPosition = (_originalPosition + (translationAxis.normalized * Mathf.Sin(Time.time * translationSpeed) * translationPeriod));
  31.  
  32.             goalRotation = Quaternion.AngleAxis(rotSpeed * Time.time, rotationAxis);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement