Guest User

CharacterPhysicsCollider

a guest
Dec 10th, 2013
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4.  
  5. [
  6.  RequireComponent(typeof(PolygonCollider2D))
  7. ]
  8. public class CharacterPhysicsCollider : MonoBehaviour
  9. {
  10.     protected Vector2[] originalPoints;
  11.  
  12.     PolygonCollider2D polygonCollider2D;
  13.  
  14.     void Start ()
  15.     {
  16.         polygonCollider2D=GetComponent<PolygonCollider2D> ();
  17.  
  18.         originalPoints=new Vector2[polygonCollider2D.points.Length];
  19.  
  20.         polygonCollider2D.points.CopyTo (originalPoints,0);
  21.     }
  22.    
  23.     void Update()
  24.     {
  25.         FixColliderRotation ();
  26.     }
  27.  
  28.     public void FixColliderRotation()
  29.     {
  30.         Vector2[] new_t=new Vector2[originalPoints.Length];
  31.        
  32.         for(int i=0;i<originalPoints.Length;i++)
  33.         {
  34.             new_t[i]=VectorConverter.ToVector2(transform.localRotation*VectorConverter.ToVector3(originalPoints[i]));
  35.         }
  36.        
  37.         polygonCollider2D.points = new_t;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment