Introduction The CreateRectangle method creates a Polygon that is in the shape of a rectangle. Polygons created through the CreateRectangle method are no different than any other Polygon – the CreateRectangle method is simply a method that simplifies a common task. Since Polygons and AxisAlignedRectangles have the same methods for performing collision and both inherit[…]


Introduction The Points property is an array of Point values which contain the position of each point on the polygon. These values are in “object space”. In other words, they are relative to the containing Polygon’s position and rotation values. The Points property can be assigned – this essentially changes the shape of the Polygon.[…]


Introduction The ProjectParentVelocityOnLastMoveCollisionTangent method is a very powerful and useful method for creating realistic collision. This method can be used in many types of games to help reduce “tunneling” – that is, objects hopping through other objects because of high speeds. What does this actually mean? The ProjectParentVelocityOnLastMoveCollisionTangent property is a very long property name[…]

FlatRedBall.Math.Geometry.Polygon.CollideAgainstMove and Attachments

Introduction Due to the popularity of the Entity pattern, it is very common to have shapes attached to other PositionedObjects. Because of this common setup, all shapes have special behavior in their collision methods to reposition or change the velocity of their TopParent. The Attachment Hierarchy The attachment hierarchy is a collection of IAttachables and[…]


Introduction The CollideAgainstMove is a method which can be used to test whether two Shapes are touching, and if they are to move one or both so that they no longer overlap. CollideAgainstMove also works between all types of shapes. The CollideAgainstMove is a very common method used in games which include solid collision. Sometimes[…]


Introduction The ICollidable interface provides a standard collision implementation. Objects which implement ICollidable can collide with all FlatRedBall shapes and other ICollidables. The ICollidable interface requires a ShapeCollection property named Collision. FlatRedBall also offers the following extension methods for ICollidable: CollideAgainst – Simply returns true/false to indicate whether a collision has occured CollideAgainstMove – Returns[…]


Introduction The CollideAgainstBounce method can be used to have two 3D shapes collide against each other and bounce (modify their or their top parent’s velocity appropriately). This function works the same as the CollideAgainstBounce provided for 2D shapes, so for a more detailed discussion, see this page. Code Example The following code creates two AxisAlignedCubes,[…]


Introduction The RepositionDirections member controls which direction colliding objects will be repositioned. Specifially RepositionDirections is relevant when calling CollideAgainstMove and CollideAgainstBounce. RepositionDirections is also used by CollisionRelationships when using By default all directions are active, meaning the rectangle will reposition objects in all directions (up, down, left, right). This value is often used when performing[…]


Introduction The IVisible interface is an interface which defines that an object must have a Visible property. Setting Visible to true or false will make the object appear or disappear visually. Most visual FlatRedBall types implement the IVisible property including: Sprite Text AxisAlignedRectangle Circle Polygon SpriteFrame Code Example The following code shows how to toggle[…]


Introduction The PolygonSave class is a “save” object which corresponds to the FlatRedBall.Math.Geometry.Polygon runtime object. For more information on the save pattern, see this page Creating a PolygonSave The following code shows how to create a PolygonSave from a Polygon: // Assuming polygonInstance is a valid Polygon PolygonSave polygonSave = PolygonSave.FromPolygon(polygonInstance); Creating a Polygon from[…]