public override void Awake() { if (collider != null) { collider.CheckDropAxis(); body = collider.connectedBody; if (body == null) { body = Physics.AddBody(); body.Position = VectorConverter.Convert(transform.position, collider.to2dMode); body.Rotation = MathHelper.ToRadians(VectorConverter.Angle(transform.rotation.eulerAngles, collider.to2dMode)); body.UserData = collider; collider.AddCollider(body, mass); } body.BodyType = (isKinematic) ? BodyType.Kinematic : BodyType.Dynamic; body.Enabled = gameObject.active; body.LinearDamping = drag; body.AngularDamping = angularDrag; body.FixedRotation = freezeRotation; RescaleMass(); if (!isKinematic) { Physics.AddRigidBody(body); } } else { #if DEBUG Debug.LogWarning("No collider set on this rigid body " + ToString()); #endif } }
public void WeWillNotHitAColliderIfTheRayStartsInsideIt() { Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on"); Body body = Physics.AddBody(); Physics.AddBox(body, false, 10, 10, new Vector2(0, 0), 1); bool hit = Physics.Raycast(Vector2.zero, Vector2.up, 100, 0); Assert.That(hit, Is.False); }
public void WeCanMissAllCollidersUsing3d() { Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on"); Body body = Physics.AddBody(); Physics.AddBox(body, false, 10, 10, new Vector2(0, 50), 1); bool hit = Physics.Raycast(Vector2.zero, Vector2.right, 100, 0); Assert.That(hit, Is.False); }
public void WeCanDetermineAColliderHitUsing3d() { Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on"); Body body = Physics.AddBody(); Physics.AddBox(body, false, 10, 10, new Vector2(0, 50), 1); bool hit = Physics.Raycast(Vector3.zero, -Vector3.forward, 100, 0); Assert.That(hit, Is.True); }
public void WeWillGetNoHitsIfThereIsNoFixturesAtThePoint() { Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on"); Body body = Physics.AddBody(); Physics.AddBox(body, false, 10, 10, new Vector2(0, 50), 1); bool hit = Physics.Pointcast(new Vector2(-5, -5)); Assert.That(hit, Is.False); }
public void WeWillGetAHitIfAFixtureIsThere() { Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on"); Body body = Physics.AddBody(); Physics.AddBox(body, false, 10, 10, new Vector2(0, 50), 1); bool hit = Physics.Pointcast(new Vector2(5, 55)); Assert.That(hit, Is.True); }
public void WeWillOnlyGetObjectsInDistance() { Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on"); Body body = Physics.AddBody(); Body body1 = Physics.AddBody(); Physics.AddBox(body1, false, 10, 10, new Vector2(0, 50), 1); Physics.AddBox(body, false, 10, 10, new Vector2(0, 20), 1); RaycastHit[] hits = Physics.RaycastAll(Vector2.zero, Vector2.up, 30, 0); Assert.That(hits.Length, Is.EqualTo(1)); }
public override void Awake() { if (rigidbody == null) { CheckDropAxis(); connectedBody = Physics.AddBody(); connectedBody.Position = VectorConverter.Convert(transform.position, to2dMode); connectedBody.Rotation = MathHelper.ToRadians(VectorConverter.Angle(transform.rotation.eulerAngles, to2dMode)); connectedBody.UserData = this; connectedBody.BodyType = BodyType.Static; AddCollider(connectedBody, 1); } }
public void WeWillGetInfOnTheClosestObjectHit() { Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on"); Body body = Physics.AddBody(); Body body1 = Physics.AddBody(); Physics.AddBox(body, false, 10, 10, new Vector2(0, 20), 1); Physics.AddBox(body1, false, 10, 10, new Vector2(0, 50), 1); RaycastHit hit = new RaycastHit(); bool hasHit = Physics.Raycast(Vector2.zero, Vector2.up, out hit, 100, 0); Assert.That(hasHit, Is.True); Assert.That(hit.body, Is.SameAs(body)); }
public void WeCanGetHitInfoOnTheObjectThatWasHit() { Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on"); Body body = Physics.AddBody(); Physics.AddBox(body, false, 10, 10, new Vector2(0, 50), 1); RaycastHit hit = new RaycastHit(); bool hasHit = Physics.Raycast(Vector2.zero, Vector2.up, out hit, 100, 0); Assert.That(hasHit, Is.True); Assert.That(hit.body, Is.SameAs(body)); Assert.That(hit.point, Is.EqualTo(new Vector3(0, 0, 45))); Assert.That(hit.normal, Is.EqualTo(new Vector3(0, 0, -1))); Assert.That(hit.distance, Is.EqualTo(45)); }