TrueSync
TSCollision2D.cs
1 using UnityEngine;
2 
3 namespace TrueSync {
4 
8  public class TSContactPoint2D {
9 
13  public TSVector2 point;
14 
18  public TSVector2 normal;
19 
20  }
21 
25  public class TSCollision2D {
26 
30  public TSContactPoint2D[] contacts = new TSContactPoint2D[1];
31 
36 
40  public GameObject gameObject;
41 
46 
51 
55  public TSVector2 relativeVelocity;
56 
57  internal void Update(GameObject otherGO, Physics2D.Contact c) {
58  if (this.gameObject == null) {
59  this.gameObject = otherGO;
60  this.collider = this.gameObject.GetComponent<TSCollider2D>();
61  this.rigidbody = this.gameObject.GetComponent<TSRigidBody2D>();
62  this.transform = this.collider.tsTransform;
63  }
64 
65  if (c != null) {
66  if (contacts[0] == null) {
67  contacts[0] = new TSContactPoint2D();
68  }
69 
70  TSVector2 normal;
71  Physics2D.FixedArray2<TSVector2> points;
72 
73  c.GetWorldManifold(out normal, out points);
74 
75  contacts[0].normal = normal;
76  contacts[0].point = points[0];
77 
78  this.relativeVelocity = c.CalculateRelativeVelocity();
79  }
80  }
81 
82  }
83 
84 }
TSRigidBody2D rigidbody
TSRigidBody of the body hit, if there is one attached
Represents information about a contact between two 2D bodies.
TSVector2 normal
Normal vector from the contact point.
Represents information about a contact point.
Definition: TSCollision2D.cs:8
GameObject gameObject
GameObject of the body hit.
TSTransform2D transform
TSTransform of the body hit
A deterministic version of Unity&#39;s Transform component for 2D physics.
Definition: TSTransform2D.cs:9
TSVector2 relativeVelocity
The TSTransform of the body hit.
TSCollider2D collider
TSCollider of the body hit
Represents a physical 2D rigid body.
Abstract collider for 2D shapes.
Definition: TSCollider2D.cs:11
TSVector2 point
Contact point between two bodies.