public void HandleCollision(GameObject obj, BoundingPolygon p, Vector collisionNormal, CollisionResult collisionResult) { if (collisionNormal.X > 0.8) { direction = 1; } else if (collisionNormal.X < -0.8) { direction = -1; } else if (obj.Velocity.X > 0) { direction = 1; } else if (obj.Velocity.X < 0) { direction = -1; } }
//Handle collisions against edges public override void Collide(BoundingPolygon p, Vector collisionNormal, CollisionResult collisionResult) { //if (collisionResult.isIntersecting) return; base.Collide(p, collisionNormal, collisionResult); // If intersecting, push back if (collisionResult.isIntersecting) { Position += collisionResult.minimumTranslationVector; } else { remainingFrameTime -= collisionResult.collisionTime; if (collisionResult.hasIntersected) Position -= (1-collisionResult.collisionTime + 1e-6) * Velocity * frameTime; else Position -= collisionResult.minimumTranslationVector; Velocity = Velocity - ((1.0+objectPhysics.Elasticity)*Velocity.DotProduct(collisionNormal))*collisionNormal; Position += remainingFrameTime * Velocity * frameTime; /* * Run the event handlers */ if (Math.Abs(collisionNormal.X) > 0.8) OnCollidedWithWall(); if (collisionNormal.Y > 0.5) { if (!OnGround) { OnLanded(); OnGround = true; } inAirTimer.Restart(); } } // } }
public override void Collide(BoundingPolygon p, Vector collisionNormal, CollisionResult collisionResult) { if (currentState == dieState) return; base.Collide (p, collisionNormal, collisionResult); if (collisionResult.hitNormal.X > 0.8 && sliding) { sliding = false; objectPhysics.Friction = oldFriction; } }
public void HandleCollision(GameObject obj, BoundingPolygon p, Vector collisionNormal, CollisionResult collisionResult) { }
public CollisionEvent(ICollidable obj, BoundingPolygon p, Vector normal, CollisionResult collisionResult) { collisionType = Type.OBJECT_POLYGON; object1 = obj; polygon = p; collisionNormal = normal; this.collisionResult = collisionResult; }
/// <summary> /// Project a convex polygon on a vector. /// </summary> private static Projection ProjectPolygon(BoundingPolygon p, Vector axis) { double min = double.PositiveInfinity, max = double.NegativeInfinity; foreach (Vector v in p.Vertices) { double dot = v.DotProduct(axis); if (dot < min) min = dot; if (dot > max) max = dot; } return new Projection(min, max, axis); }
/// <summary> /// From ICloneable /// </summary> public object Clone() { BoundingPolygon p = new BoundingPolygon(vertices); p.MoveTo(center.X, center.Y); return p; //return new BoundingPolygon(vertices); }
/// <summary> /// Create a new tile /// </summary> public Tile(int id, Texture texture, BoundingPolygon boundingPolygon) { this.Id = id; this.BoundingPolygon = boundingPolygon; this.Texture = texture; }
public virtual void Collide(BoundingPolygon p, Vector collisionNormal, CollisionResult collisionResult) { if (controller != null) controller.HandleCollision(this, p, collisionNormal, collisionResult); }