private static void DrawPlaneCollider(PlaneCollider collider) { SceneObject so = collider.SceneObject; Vector3 normal = collider.Normal; Vector3 center = normal * collider.Distance; // Rotate around origin Quaternion rotation = Quaternion.FromToRotation(Vector3.XAxis, normal); Matrix4 rotMatrix = Matrix4.TRS(center, Quaternion.Identity, Vector3.One) * Matrix4.TRS(Vector3.Zero, rotation, Vector3.One) * Matrix4.TRS(-center, Quaternion.Identity, Vector3.One); Gizmos.Color = Color.Green; Gizmos.Transform = Matrix4.TRS(so.Position, so.Rotation, Vector3.One) * rotMatrix; Vector3 bottomLeft = new Vector3(0.0f, -0.5f, -0.5f); Vector3 topLeft = new Vector3(0.0f, 0.5f, -0.5f); Vector3 topRight = new Vector3(0.0f, 0.5f, 0.5f); Vector3 bottomRight = new Vector3(0.0f, -0.5f, 0.5f); bottomLeft += center; topLeft += center; topRight += center; bottomRight += center; // Draw sides Gizmos.DrawLine(bottomLeft, topLeft); Gizmos.DrawLine(topLeft, topRight); Gizmos.DrawLine(topRight, bottomRight); Gizmos.DrawLine(bottomRight, bottomLeft); // Draw normal Gizmos.DrawLine(center, center + Vector3.XAxis * 0.5f); }
private void OnCollisionHandler(object sender, EventArgs e) { UObject who = ((CollisionEventArgs)e).Who; switch (who.Collider.Type) { case Collider2DType.PlaneY: { PlaneCollider cldr = who.Collider as PlaneCollider; Position.Y = cldr.Tupal - _radius; Velocity.Y *= -0.8f; float diffVel = _lastVelocity - System.Math.Abs(Velocity.Y); if (System.Math.Abs(diffVel) < 0.05f) { _isMoving = false; } _lastVelocity = System.Math.Abs(Velocity.Y); } break; case Collider2DType.Circle: { // Need to get collision point } break; } }
public override void Initialize() { base.Initialize(); this.transform.SetPosition(new Vector2(240f, 840f)); collider = (PlaneCollider)AddComponent <PlaneCollider>(); collider.SetColliderDimensions(true, 1400); image = new Image("Graphics/Tower", transform.position, 1, 1); }
public void Point_PlaneTest1() { PE.ParticleSystem ps = new PE.ParticleSystem(); ps.Add(new Particle(new PE.Vec3(1, 0, 2), new PE.Vec3(0, 0, 0), 0.0, 0, 0)); PlaneCollider pl1 = new PlaneCollider(new Entity(), new PE.Vec3(0, 0, 1), 1.0); Assert.IsFalse(Collider.CheckIntersection(ps, pl1).Count != 0); }
public override void Initialize() { base.Initialize(); this.transform.SetPosition(new Vector2(0f, SceneManager.Instance.virtualHeight - 10)); collider = (PlaneCollider)AddComponent <PlaneCollider>(); collider.SetColliderDimensions(true, 1900); image = new Image("Graphics/Tower", transform.position, 1, 1); }
/// <inheritdoc/> protected internal override void Initialize() { PlaneCollider collider = InspectedObject as PlaneCollider; if (collider != null) { BuildGUI(collider); } }
public override void OnCollision(PlaneCollider other, Vector2 normal) { base.OnCollision(other, normal); // On collision with a plane collider, if we are above the collider, we can jump. if (other.position.Y > this.circleCollider.center.Y) { canJump = true; } }
public SimpleGround(float ground, Collider2DType type) { _controller = new NullController(); Collider = new PlaneCollider(type, ground); Collider.CollisionEvent += OnCollisionHandler; _transform = new Transform(); _key = Guid.NewGuid().ToString(); Ground = ground; }
public virtual void OnCollision(PlaneCollider other, Vector2 normal) { // PlaneColliders use physics. PhysicsBody physicsBody = GetComponent <PhysicsBody>() as PhysicsBody; if (physicsBody != null) { physicsBody.CollisionResolution(other, normal); } }
/// <summary> /// Updates all GUI elements from current values in the collider. /// </summary> /// <param name="collider">Collider to update the GUI from.</param> protected void Refresh(PlaneCollider collider) { if (!normalField.HasInputFocus) { normalField.Value = normal; } if (!distanceField.HasInputFocus) { distanceField.Value = collider.Distance; } base.Refresh(collider); }
public static BlobAssetReference <QuadTreeBlob> CreateBlobAssetReference(HitQuadTree hitQuadTree, HitPlane playfield, HitPlane glass) { using (var builder = new BlobBuilder(Allocator.Temp)) { ref var rootQuadTree = ref builder.ConstructRoot <QuadTreeBlob>(); QuadTree.Create(hitQuadTree, ref rootQuadTree.QuadTree, builder); if (playfield != null) { PlaneCollider.Create(builder, playfield, ref rootQuadTree.PlayfieldCollider); } else { ref var playfieldCollider = ref builder.Allocate(ref rootQuadTree.PlayfieldCollider); playfieldCollider.Header = new ColliderHeader { Type = ColliderType.None }; }
/// <inheritdoc/> protected internal override InspectableState Refresh() { PlaneCollider collider = InspectedObject as PlaneCollider; if (collider == null) { return(InspectableState.NotModified); } Refresh(collider); InspectableState oldState = modifyState; if (modifyState.HasFlag(InspectableState.Modified)) { modifyState = InspectableState.NotModified; } return(oldState); }
public void Sphere_PlaneTest() { Sphere s = new Sphere(new Vec3(0, 1, 0), 1.5, 1); PlaneCollider p = new PlaneCollider(new Entity(), new Vec3(0, 1, 0), 0); PE.SphereCollider sc = new PE.SphereCollider(s); List <Intersection> intersections = p.CheckIntersection(s); Intersection intersection = intersections[0]; Vec3 normal = intersection.normal; Vec3 point = intersection.point; double penetration = intersection.distance; Console.WriteLine("Normal: " + normal); Console.WriteLine("Point: " + point); Console.WriteLine("Penetration: " + penetration); Assert.IsTrue(normal.Equals(new Vec3(0, 1, 0)) && point.Equals(new Vec3(0, 0, 0)) && penetration == 0.5); }
/// <summary> /// Creates GUI elements for fields specific to the plane collider. /// </summary> protected void BuildGUI(PlaneCollider collider) { normalField.OnValueChanged += x => { normal = x; collider.Normal = x; MarkAsModified(); }; normalField.OnFocusLost += ConfirmModify; normalField.OnConfirm += x => ConfirmModify(); distanceField.OnChanged += x => { collider.Distance = x; MarkAsModified(); }; distanceField.OnFocusLost += ConfirmModify; distanceField.OnConfirmed += ConfirmModify; Layout.AddElement(normalField); Layout.AddElement(distanceField); normal = collider.Normal; base.BuildGUI(collider); }
public virtual void OnCollision(object sender, EventArgs e) { if (e is CollisionEventArgs) { CollisionEventArgs ce = (CollisionEventArgs)e; switch (ce.Who.Collider.Type) { case Collider2DType.PlaneY: { PlaneCollider pc = (PlaneCollider)ce.Who.Collider; if (ce.Location == CollisionEventArgs.HitLocation.Top) { Position.Y = ce.Points[0].Y; } else { Position.Y = ce.Points[0].Y - (((CircleCollider)Collider).Radius * 2); } } break; case Collider2DType.PlaneX: { PlaneCollider pc = (PlaneCollider)ce.Who.Collider; if (ce.Location == CollisionEventArgs.HitLocation.Left) { Position.X = pc.Tupal; } else { Position.X = pc.Tupal - (((CircleCollider)Collider).Radius * 2); } } break; } } }
public bool Intersect(PlaneCollider other) { float VC = 0.0f; return(other.SphereCollisionOccured(this, 1.0f / 60.0f, ref VC)); }
public static CollisionPoints FindSpherePlaneCollisionPoints( SphereCollider a, Transform ta, PlaneCollider b, Transform tb) { return(new CollisionPoints()); }