Advertisement
VelhoRabugento

Teste3

Oct 22nd, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 22.67 KB | None | 0 0
  1. // External release version 1.1.0
  2.  
  3. using UnityEngine;
  4. using System;
  5. using System.Linq;
  6. using System.Collections.Generic;
  7.  
  8. /// <summary>
  9. /// Custom character controller, to be used by attaching the component to an object
  10. /// and writing scripts attached to the same object that recieve the "SuperUpdate" message
  11. /// </summary>
  12. public class SuperCharacterController : MonoBehaviour
  13. {
  14.     [SerializeField]
  15.     public Vector3 debugMove = Vector3.zero;
  16.  
  17.     [SerializeField]
  18.     bool fixedTimeStep;
  19.  
  20.     [SerializeField]
  21.     int fixedUpdatesPerSecond;
  22.  
  23.     [SerializeField]
  24.     bool debugSpheres;
  25.  
  26.     [SerializeField]
  27.     bool debugPushbackMesssages;
  28.  
  29.     /// <summary>
  30.     /// Describes the Transform of the object we are standing on as well as it's CollisionType, as well
  31.     /// as how far the ground is below us and what angle it is in relation to the controller.
  32.     /// </summary>
  33.     [SerializeField]
  34.     public struct Ground
  35.     {
  36.         public RaycastHit Hit;
  37.         public RaycastHit NearHit;
  38.         public RaycastHit FarHit;
  39.         public SuperCollisionType CollisionType;
  40.         public Transform Transform;
  41.  
  42.         public Ground(RaycastHit hit, RaycastHit nearHit, RaycastHit farHit, SuperCollisionType superCollisionType, Transform hitTransform)
  43.         {
  44.             Hit = hit;
  45.             NearHit = nearHit;
  46.             FarHit = farHit;
  47.             CollisionType = superCollisionType;
  48.             Transform = hitTransform;
  49.         }
  50.     }
  51.  
  52.     [SerializeField]
  53.     CollisionSphere[] spheres =
  54.         new CollisionSphere[3] {
  55.             new CollisionSphere(0.5f, true, false),
  56.             new CollisionSphere(1.0f, false, false),
  57.             new CollisionSphere(1.5f, false, true),
  58.         };
  59.  
  60.     public LayerMask Walkable;
  61.  
  62.     [SerializeField]
  63.     Collider OwnCollider;
  64.  
  65.     public float radius = 0.5f;
  66.  
  67.     public float deltaTime { get; private set; }
  68.     public Ground currentGround { get; private set; }
  69.     public CollisionSphere feet { get; private set; }
  70.     public CollisionSphere head { get; private set; }
  71.     public float height { get { return Vector3.Distance(OffsetPosition(head.Offset), OffsetPosition(feet.Offset)); } }
  72.     public Vector3 up { get { return transform.up; } }
  73.     public Vector3 down { get { return -transform.up; } }
  74.     public List<SuperCollision> collisionData { get; private set; }
  75.     public Transform currentlyClampedTo { get; set; }
  76.  
  77.     private Vector3 initialPosition;
  78.     private Vector3 groundOffset;
  79.     private bool clamping = true;
  80.     private bool slopeLimiting = true;
  81.  
  82.     private List<Collider> ignoredColliders;
  83.     private List<IgnoredCollider> ignoredColliderStack;
  84.  
  85.     private const float Tolerance = 0.05f;
  86.     private const float TinyTolerance = 0.01f;
  87.     private const string TemporaryLayer = "TempCast";
  88.     private int TemporaryLayerIndex;
  89.     private float fixedDeltaTime;
  90.  
  91.     public float speed = 26f;
  92.     public float torque;
  93.     public float maxVelocidade;
  94.     public float velocidadeAtual;
  95.     private float maxVelocity;
  96.     public float velocidadeLimite;
  97.  
  98.     public float jumpSpeed = 8f;
  99.     public float friction = 1f;
  100.     private Vector3 currentVelocity = Vector3.zero;
  101.     private float velocityY = 0f;
  102.     private SuperCharacterController character;
  103.  
  104.     public float SlideAngle = 30.0f;
  105.     public float SlideContinueAngle = 30.0f;
  106.     public bool Destructable;
  107.  
  108.     public void Awake()
  109.     {
  110.         collisionData = new List<SuperCollision>();
  111.  
  112.         TemporaryLayerIndex = LayerMask.NameToLayer(TemporaryLayer);
  113.  
  114.         ignoredColliders = new List<Collider>();
  115.         ignoredColliderStack = new List<IgnoredCollider>();
  116.  
  117.         currentlyClampedTo = null;
  118.  
  119.         fixedDeltaTime = 1.0f / fixedUpdatesPerSecond;
  120.  
  121.         if (OwnCollider)
  122.             IgnoreCollider(OwnCollider);
  123.  
  124.         foreach (var sphere in spheres)
  125.         {
  126.             if (sphere.IsFeet)
  127.                 feet = sphere;
  128.  
  129.             if (sphere.IsHead)
  130.                 head = sphere;
  131.         }
  132.  
  133.         if (feet == null)
  134.             Debug.LogError("[SuperCharacterController] Feet not found on controller");
  135.  
  136.         if (head == null)
  137.             Debug.LogError("[SuperCharacterController] Head not found on controller");
  138.            
  139.         gameObject.SendMessage("SuperStart", SendMessageOptions.DontRequireReceiver);
  140.     }
  141.  
  142.     void Start()
  143.     {
  144.         // maxVelocity = maxVelocidade * 3.6f;
  145.         velocidadeAtual = 0f;
  146.         maxVelocidade = 5f;
  147.         velocidadeLimite = 5f;
  148.  
  149.         SlideAngle = Mathf.Clamp(SlideAngle, SlideContinueAngle, Mathf.Infinity);
  150.     }
  151.  
  152.     void Update()
  153.     {
  154.         // If we are using a fixed timestep, ensure we run the main update loop
  155.         // a sufficient number of times based on the Time.deltaTime
  156.  
  157.         if (!fixedTimeStep)
  158.         {
  159.             deltaTime = Time.deltaTime;
  160.  
  161.             SingleUpdate();
  162.             return;
  163.         }
  164.         else
  165.         {
  166.             float delta = Time.deltaTime;
  167.  
  168.             while (delta > fixedDeltaTime)
  169.             {
  170.                 deltaTime = fixedDeltaTime;
  171.  
  172.                 SingleUpdate();
  173.  
  174.                 delta -= fixedDeltaTime;
  175.             }
  176.  
  177.             if (delta > 0f)
  178.             {
  179.                 deltaTime = delta;
  180.  
  181.                 SingleUpdate();
  182.             }
  183.  
  184.         }
  185.  
  186.         if (Input.GetKey("w") && velocidadeLimite >= maxVelocidade)
  187.         {
  188.             velocidadeAtual = maxVelocidade;
  189.             speed = 2f;
  190.             SlideAngle = 4f;
  191.             SlideContinueAngle = 4f;
  192.  
  193.             Debug.Log(velocidadeAtual);
  194.         }
  195.  
  196.         else
  197.         {
  198.             velocidadeAtual = 0f;
  199.             SlideAngle = 30f;
  200.             SlideContinueAngle = 30f;
  201.         }
  202.  
  203.         if (Input.GetKey("s") && velocidadeAtual <= maxVelocidade)
  204.         {
  205.             //velocidadeAtual = maxVelocidade;
  206.             velocidadeAtual--;
  207.             speed = 2f;
  208.  
  209.             Debug.Log(velocidadeAtual);
  210.  
  211.             if (velocidadeAtual <= 0f)
  212.             {
  213.                 velocidadeAtual = 2f;
  214.                 SlideAngle = 4f;
  215.                 SlideContinueAngle = 4f;
  216.             }
  217.             else
  218.             {
  219.                 velocidadeAtual = 0f;
  220.                 SlideAngle = 30f;
  221.                 SlideContinueAngle = 30f;
  222.             }
  223.         }
  224.  
  225.             if (!character)
  226.             {
  227.                 // get the CharacterController only the first time:
  228.                 character = GetComponent<SuperCharacterController>();
  229.                 // get the direction from the controls:
  230.                 Vector3 dir = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
  231.                 // calculate the desired velocity:
  232.                 Vector3 vel = transform.TransformDirection(dir) * speed;
  233.  
  234.                 // here's where the magic happens:
  235.                 currentVelocity = Vector3.Lerp(currentVelocity, vel, friction * Time.deltaTime);
  236.  
  237.                 // apply gravity and jump after the friction!
  238.                 if (character.clamping)
  239.                 {
  240.                     velocityY = 0;
  241.                 }
  242.                 if (Input.GetButtonDown("Jump"))
  243.                 {
  244.                     velocityY = jumpSpeed;
  245.                     velocityY -= Time.deltaTime;
  246.                     currentVelocity.y = velocityY;
  247.                     currentVelocity = (currentVelocity * Time.deltaTime);
  248.                 }
  249.             }
  250.         }
  251.  
  252.     private void OnTriggerStay(Collider other) {
  253.  
  254.         if (other.gameObject.tag == "IceFloor")
  255.         {
  256.             Debug.Log("Gelo!");
  257.  
  258.             if (Input.GetKey("w") && velocidadeLimite >= maxVelocidade)
  259.             {
  260.                 velocidadeAtual = maxVelocidade;
  261.                 SlideAngle = 4f;
  262.                 SlideContinueAngle = 4f;
  263.             }
  264.             else
  265.             {
  266.                 velocidadeAtual = 0f;
  267.                 SlideAngle = 30f;
  268.                 SlideContinueAngle = 30f;
  269.             }
  270.  
  271.             speed = 2f;
  272.  
  273.             Debug.Log("Aumentou velocidade");
  274.  
  275.             float moveHorizontal = Input.GetAxis("Horizontal");
  276.             float moveVertical = Input.GetAxis("Vertical");
  277.  
  278.             Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
  279.  
  280.             GetComponent<Collider>().material.dynamicFriction = 0.1f;
  281.  
  282.             GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
  283.  
  284.             //Mathf.Clamp(GetComponent<Rigidbody>().velocity.x, 0, 3);
  285.             //gameObject.GetComponent<Rigidbody>().velocity *= 0.99f;
  286.  
  287.             //velocidadeAtual = Mathf.Abs(gameObject.GetComponent<Rigidbody>().velocity.sqrMagnitude / 3.6f);
  288.  
  289.         }
  290.  
  291.  
  292.         else if (other.gameObject.tag == "IceFloor")
  293.         {
  294.             Debug.Log("Gelo!");
  295.  
  296.             if (Input.GetKey("s") && velocidadeAtual <= maxVelocidade)
  297.  
  298.             //velocidadeAtual = maxVelocidade;
  299.             velocidadeAtual--;
  300.             SlideAngle = 4f;
  301.             SlideContinueAngle = 4f;
  302.  
  303.             if (velocidadeAtual <= 0f)
  304.             {
  305.                 velocidadeAtual = 2f;
  306.             }
  307.             else
  308.             {
  309.                 velocidadeAtual = 0f;
  310.                 SlideAngle = 30f;
  311.                 SlideContinueAngle = 30f;
  312.             }
  313.  
  314.             speed = 2f;
  315.  
  316.             Debug.Log("Diminuiu velocidade");
  317.  
  318.             float moveHorizontal = Input.GetAxis("Horizontal");
  319.             float moveVertical = Input.GetAxis("Vertical");
  320.  
  321.             Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
  322.  
  323.             GetComponent<Collider>().material.dynamicFriction = 0.5f;
  324.             GetComponent<Rigidbody>().AddForce(movement * speed / 2 * Time.deltaTime);
  325.  
  326.             //gameObject.GetComponent<Rigidbody>().velocity *= 0.33f;
  327.  
  328.             //velocidadeAtual = Mathf.Abs(gameObject.GetComponent<Rigidbody>().velocity.sqrMagnitude / 3.6f);
  329.         }
  330.     }
  331.    
  332.     public void antiUpwarp(){
  333.         Walkable = 0;
  334.     }
  335.  
  336.     void SingleUpdate()
  337.     {
  338.         // Check if we are clamped to an object implicity or explicity
  339.         bool isClamping = clamping || currentlyClampedTo != null;
  340.         Transform clampedTo = currentlyClampedTo != null ? currentlyClampedTo : currentGround.Transform;
  341.  
  342.         // Move our controller if clamped object moved in the previous frame
  343.         if (isClamping && groundOffset != Vector3.zero && clampedTo != null)
  344.             transform.position = clampedTo.position + groundOffset;
  345.  
  346.         initialPosition = transform.position;
  347.  
  348.         ProbeGroundRecursive();
  349.  
  350.         transform.position += debugMove * deltaTime;
  351.  
  352.         gameObject.SendMessage("SuperUpdate", SendMessageOptions.DontRequireReceiver);
  353.  
  354.         Pushback();
  355.  
  356.         ProbeGroundRecursive();
  357.  
  358.         if (slopeLimiting)
  359.             SlopeLimit();
  360.  
  361.         ProbeGroundRecursive();
  362.  
  363.         if (clamping)
  364.             ClampToGround();
  365.  
  366.         isClamping = clamping || currentlyClampedTo != null;
  367.         clampedTo = currentlyClampedTo != null ? currentlyClampedTo : currentGround.Transform;
  368.  
  369.         if (isClamping)
  370.             groundOffset = transform.position - clampedTo.position;
  371.  
  372.     }
  373.  
  374.     /// <summary>
  375.     /// Prevents the player from walking up slopes of a larger angle than the object's SlopeLimit.
  376.     /// NOTE: Since ProbeGroundRecursive ignores any slopes greater than StandAngle, the controller
  377.     /// will not be slope limited against these slopes.
  378.     /// </summary>
  379.     /// <returns>True if the controller attemped to ascend a too steep slope and had their movement limited</returns>
  380.     bool SlopeLimit()
  381.     {
  382.         Vector3 n = currentGround.Hit.normal;
  383.         float a = Vector3.Angle(n, up);
  384.  
  385.         if (a > currentGround.CollisionType.SlopeLimit)
  386.         {
  387.             Vector3 absoluteMoveDirection = Math3d.ProjectVectorOnPlane(n, transform.position - initialPosition);
  388.  
  389.             // Retrieve a vector pointing down the slope
  390.             Vector3 r = Vector3.Cross(n, down);
  391.             Vector3 v = Vector3.Cross(r, n);
  392.  
  393.             float angle = Vector3.Angle(absoluteMoveDirection, v);
  394.  
  395.             if (angle <= 90.0f)
  396.                 return false;
  397.  
  398.             // Calculate where to place the controller on the slope, or at the bottom, based on the desired movement distance
  399.             Vector3 resolvedPosition = Math3d.ProjectPointOnLine(initialPosition, r, transform.position);
  400.             Vector3 direction = Math3d.ProjectVectorOnPlane(n, resolvedPosition - transform.position);
  401.  
  402.             RaycastHit hit;
  403.  
  404.             // Check if our path to our resolved position is blocked by any colliders
  405.             if (Physics.CapsuleCast(OffsetPosition(feet.Offset), OffsetPosition(head.Offset), radius, direction.normalized, out hit, direction.magnitude, Walkable))
  406.             {
  407.                 transform.position += v.normalized * hit.distance;
  408.             }
  409.             else
  410.             {
  411.                 transform.position += direction;
  412.             }
  413.  
  414.             return true;
  415.         }
  416.  
  417.         return false;
  418.     }
  419.  
  420.     void ClampToGround()
  421.     {
  422.         float d = currentGround.Hit.distance;
  423.         transform.position -= up * d;
  424.     }
  425.  
  426.     public void EnableClamping()
  427.     {
  428.         clamping = true;
  429.     }
  430.  
  431.     public void DisableClamping()
  432.     {
  433.         clamping = false;
  434.     }
  435.  
  436.     public void EnableSlopeLimit()
  437.     {
  438.         slopeLimiting = true;
  439.     }
  440.  
  441.     public void DisableSlopeLimit()
  442.     {
  443.         slopeLimiting = false;
  444.     }
  445.  
  446.     public bool IsClamping()
  447.     {
  448.         return clamping;
  449.     }
  450.  
  451.     /// <summary>
  452.     /// SphereCasts directly below the controller recurisvely until it either finds no ground, or a ground
  453.     /// at an angle less than StandAngle
  454.     /// </summary>
  455.     void ProbeGroundRecursive()
  456.     {
  457.         ProbeGroundRecursive(OffsetPosition(feet.Offset), 0);
  458.     }
  459.  
  460.     void ProbeGroundRecursive(Vector3 origin, float distanceTraveled)
  461.     {
  462.         PushIgnoredColliders();
  463.  
  464.         // Add a small amount of Tolerance before casting downwards
  465.         Vector3 o = origin + (up * Tolerance);
  466.        
  467.         RaycastHit hit;
  468.  
  469.         if (Physics.SphereCast(o, radius, down, out hit, Mathf.Infinity, Walkable))
  470.         {
  471.             var wall = hit.collider.gameObject.GetComponent<SuperCollisionType>();
  472.  
  473.             if (wall == null)
  474.             {
  475.                 // TODO: just use some derived default values?
  476.                 Debug.LogError("[SuperCharacterComponent]: Object on SuperCharacterController walkable layer does not have SuperCollisionType component attached");
  477.             }
  478.  
  479.             Vector3 newOrigin = o + down * (hit.distance + TinyTolerance + Tolerance);
  480.  
  481.             hit.distance = Mathf.Clamp(hit.distance - Tolerance, 0, Mathf.Infinity);
  482.  
  483.             hit.distance += distanceTraveled;
  484.  
  485.             // If the StandAngle is not satisfactory, adjust our origin to be slightly below where we last hit
  486.             // and SphereCast again
  487.             if (Vector3.Angle(hit.normal, up) > wall.StandAngle)
  488.             {
  489.                 PopIgnoredColliders();
  490.  
  491.                 ProbeGroundRecursive(newOrigin, hit.distance + TinyTolerance);
  492.                 return;
  493.             }
  494.            
  495.             // Because when SphereCast hits an edge on a surface it returns the interpolation of the two normals of the
  496.             // two triangles joined to that edge, we need to retrieve the actual normal of both of the triangles
  497.             Vector3 toCenter = Math3d.ProjectVectorOnPlane(up, (transform.position - hit.point).normalized * TinyTolerance);
  498.  
  499.             if (toCenter == Vector3.zero)
  500.             {
  501.                 currentGround = new Ground(hit, hit, hit, wall, hit.transform);
  502.                 PopIgnoredColliders();
  503.  
  504.                 return;
  505.             }
  506.            
  507.             Vector3 awayFromCenter = Quaternion.AngleAxis(-80.0f, Vector3.Cross(toCenter, up)) * -toCenter;
  508.  
  509.             Vector3 nearPoint = hit.point + toCenter + (up * TinyTolerance);
  510.             Vector3 farPoint = hit.point + (awayFromCenter * 3);
  511.  
  512.             RaycastHit nearHit;
  513.             RaycastHit farHit;
  514.  
  515.             // Retrieve the normal of the point nearest to the center of the base of the controller
  516.             Physics.Raycast(nearPoint, down, out nearHit, Mathf.Infinity, Walkable);
  517.             // Retrieve the normal of the point furthest to the center of the base of the controller
  518.             Physics.Raycast(farPoint, down, out farHit, Mathf.Infinity, Walkable);
  519.  
  520.             currentGround = new Ground(hit, nearHit, farHit, wall, hit.transform);
  521.         }
  522.         else
  523.         {
  524.             // Debug.LogError("[SuperCharacterComponent]: No ground was found below the player; player has escaped level");
  525.         }
  526.  
  527.         PopIgnoredColliders();
  528.     }
  529.  
  530.     /// <summary>
  531.     /// Check if any of the CollisionSpheres are colliding with any walkable objects in the world.
  532.     /// If they are, apply a proper pushback and retrieve the collision data
  533.     /// </summary>
  534.     void Pushback()
  535.     {
  536.         PushIgnoredColliders();
  537.  
  538.         collisionData.Clear();
  539.  
  540.         foreach (var sphere in spheres)
  541.         {
  542.             foreach (Collider col in Physics.OverlapSphere(OffsetPosition(sphere.Offset), radius, Walkable))
  543.             {
  544.                 Vector3 position = OffsetPosition(sphere.Offset);
  545.                 Vector3 contactPoint = SuperCollider.ClosestPointOnSurface(col, position, radius);
  546.  
  547.                 if (contactPoint != Vector3.zero)
  548.                 {
  549.                     if (debugPushbackMesssages)
  550.                         DebugDraw.DrawMarker(contactPoint, 2.0f, Color.cyan, 0.0f, false);
  551.  
  552.                     Vector3 v = contactPoint - position;
  553.  
  554.                     if (v != Vector3.zero)
  555.                     {
  556.                         // Cache the collider's layer so that we can cast against it
  557.                         int layer = col.gameObject.layer;
  558.  
  559.                         col.gameObject.layer = TemporaryLayerIndex;
  560.  
  561.                         // Check which side of the normal we are on
  562.                         bool facingNormal = Physics.SphereCast(new Ray(position, v.normalized), TinyTolerance, v.magnitude + TinyTolerance, 1 << TemporaryLayerIndex);
  563.  
  564.                         col.gameObject.layer = layer;
  565.  
  566.                         // Orient and scale our vector based on which side of the normal we are situated
  567.                         if (facingNormal)
  568.                         {
  569.                             if (Vector3.Distance(position, contactPoint) < radius)
  570.                             {
  571.                                 v = v.normalized * (radius - v.magnitude) * -1;
  572.                             }
  573.                             else
  574.                             {
  575.                                 // A previously resolved collision has had a side effect that moved us outside this collider
  576.                                 continue;
  577.                             }
  578.                         }
  579.                         else
  580.                         {
  581.                             v = v.normalized * (radius + v.magnitude);
  582.                         }
  583.  
  584.                         transform.position += v;
  585.  
  586.                         col.gameObject.layer = TemporaryLayerIndex;
  587.  
  588.                         // Retrieve the surface normal of the collided point
  589.                         RaycastHit normalHit;
  590.  
  591.                         Physics.SphereCast(new Ray(position + v, contactPoint - (position + v)), TinyTolerance, out normalHit, 1 << TemporaryLayerIndex);
  592.  
  593.                         col.gameObject.layer = layer;
  594.  
  595.                         // Our collision affected the collider; add it to the collision data
  596.                         var collision = new SuperCollision()
  597.                         {
  598.                             collisionSphere = sphere,
  599.                             superCollisionType = col.gameObject.GetComponent<SuperCollisionType>(),
  600.                             gameObject = col.gameObject,
  601.                             point = contactPoint,
  602.                             normal = normalHit.normal
  603.                         };
  604.  
  605.                         collisionData.Add(collision);
  606.                     }
  607.                 }
  608.             }
  609.         }
  610.        
  611.         PopIgnoredColliders();
  612.     }
  613.  
  614.     protected struct IgnoredCollider
  615.     {
  616.         public Collider collider;
  617.         public int layer;
  618.  
  619.         public IgnoredCollider(Collider collider, int layer)
  620.         {
  621.             this.collider = collider;
  622.             this.layer = layer;
  623.         }
  624.     }
  625.  
  626.     private void PushIgnoredColliders()
  627.     {
  628.         ignoredColliderStack.Clear();
  629.  
  630.         for (int i = 0; i < ignoredColliders.Count; i++)
  631.         {
  632.             Collider col = ignoredColliders[i];
  633.             ignoredColliderStack.Add(new IgnoredCollider(col, col.gameObject.layer));
  634.             col.gameObject.layer = TemporaryLayerIndex;
  635.         }
  636.     }
  637.  
  638.     private void PopIgnoredColliders()
  639.     {
  640.         for (int i = 0; i < ignoredColliderStack.Count; i++)
  641.         {
  642.             IgnoredCollider ic = ignoredColliderStack[i];
  643.             ic.collider.gameObject.layer = ic.layer;
  644.         }
  645.  
  646.         ignoredColliderStack.Clear();
  647.     }
  648.  
  649.     void OnDrawGizmos()
  650.     {
  651.         if (debugSpheres)
  652.         {
  653.             if (spheres != null)
  654.             {
  655.                 foreach (var sphere in spheres)
  656.                 {
  657.                     Gizmos.color = sphere.IsFeet ? Color.green : (sphere.IsHead ? Color.yellow : Color.cyan);
  658.                     Gizmos.DrawWireSphere(OffsetPosition(sphere.Offset), radius);
  659.                 }
  660.             }
  661.         }
  662.     }
  663.  
  664.     public Vector3 OffsetPosition(float y)
  665.     {
  666.         Vector3 p;
  667.  
  668.         p = transform.position;
  669.  
  670.         p += up * y;
  671.  
  672.         return p;
  673.     }
  674.  
  675.     public bool BelowHead(Vector3 point)
  676.     {
  677.         return Vector3.Angle(point - OffsetPosition(head.Offset), up) > 89.0f;
  678.     }
  679.  
  680.     public bool AboveFeet(Vector3 point)
  681.     {
  682.         return Vector3.Angle(point - OffsetPosition(feet.Offset), down) > 89.0f;
  683.     }
  684.  
  685.     public void IgnoreCollider(Collider col)
  686.     {
  687.         ignoredColliders.Add(col);
  688.     }
  689.  
  690.     public void RemoveIgnoredCollider(Collider col)
  691.     {
  692.         ignoredColliders.Remove(col);
  693.     }
  694.  
  695.     public void ClearIgnoredColliders()
  696.     {
  697.         ignoredColliders.Clear();
  698.     }
  699. }
  700.  
  701. [Serializable]
  702. public class CollisionSphere
  703. {
  704.     public float Offset;
  705.     public bool IsFeet;
  706.     public bool IsHead;
  707.  
  708.     public CollisionSphere(float offset, bool isFeet, bool isHead)
  709.     {
  710.         Offset = offset;
  711.         IsFeet = isFeet;
  712.         this.IsHead = isHead;
  713.     }
  714. }
  715.  
  716. public struct SuperCollision
  717. {
  718.     public CollisionSphere collisionSphere;
  719.     public SuperCollisionType superCollisionType;
  720.     public GameObject gameObject;
  721.     public Vector3 point;
  722.     public Vector3 normal;
  723. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement