Advertisement
EdibleCookie

Rail Script

Apr 17th, 2018
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. // using UnityEditor;
  5.  
  6.  
  7. [ExecuteInEditMode]
  8. public class Rail : MonoBehaviour
  9. {
  10.     private Transform[] nodes;
  11.  
  12.  
  13.     private void Start()
  14.     {
  15.  
  16.         nodes = GetComponentsInChildren<Transform>();
  17.  
  18.     }
  19.  
  20.     public Vector3 LinearPosition(int seg, float ratio)
  21.     {
  22.  
  23.         Vector3 p1 = nodes[seg].position;
  24.         Vector3 p2 = nodes[seg + 1].position;
  25.         Vector3 p3 = nodes[seg+ 2].position;
  26.  
  27.         return Vector3.Lerp(p1, p2, ratio);
  28.  
  29.     }
  30.  
  31.      public Quaternion Orientation(int seg, float ratio)
  32.     {
  33.    
  34.         Quaternion q1 = nodes[seg].rotation;
  35.         Quaternion q2 = nodes[seg + 1].rotation;
  36.  
  37.         return Quaternion.Lerp(q1, q2, ratio); }
  38.    
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement