-
Notifications
You must be signed in to change notification settings - Fork 4
2D Collisions
In 2D, collision is handled via Shape2D
instances. The Shape2D
interface tracks a 2D point location (typically the centre of the mask) and provides some collision / distance methods.
It should be noted that all of these collision / distance methods should operate on any Shape2D
object. There is a defined hierarchy of collision masks (see below). Each class that implements Shape2D
should have custom logic for interactions with itself, and for interactions with classes that are higher on the hierarchy than itself. In dealings with classes that are lower on the hierarchy, other.methodName(this)
should be called to. This avoids code duplication, and saves people from having to add code to every single Shape2D
when they make a new class that implements the interface.
The hierarchy (so far) is as follows:
Point2D
Circle2D
Box2D
Line2D
(If you want to make a new Shape2D
, please add it after Line2D
)
Firstly, there are 5 trivial methods that are simply getters / setters for the x/y location of the mask and a copy method. The x/y points do not necessarily have to be the centre of the mask, as that may be hard to define for more complicated masks, but if it could be the centre of the mask that would be nice.
Secondly, there are 2 distance
methods. The first of these takes another Shape2D
object, and calculates the minimum edge-to-edge distance between them.
In the case of the square and circle in the above diagram, though other lines could be drawn from the edge of the circle to the edge of the square, they would not be as short. As such, it is the length of the line featured in this diagram that should be returned by the distance
method in this case.
If the two collision masks overlap in any way, a negative number should be returned by this method.
The other distance
method takes 4 floats as arguments, which represent the starting and stopping x,y coordinates of a line segment. This method should return the minimum distance from the edge of the collision mask to the line. If the line intersects the collision mask, it should return a negative number, much like the other distance
method. Below is a diagram of the expected behavior of this method in some example cases.
Finally, there is an overlaps
method. Functionally, this is equivalent to calling distance
with the same arguments, and seeing if the result is negative or not. However, there are some optimisations that can be made if all you need to calculate is whether two objects intersect, instead of how far away they are. This method should follow the same hierarchy as the distance
method.
- Home
- How To Play
- Keybindings
- Inventory and Resources
- Trees
- Portals and Worlds
- Projectiles
- Enemies
- Waves & Spawning
- Graphical assets progress overview
- Audio Files
- Design Templates
- Blender Intro
- Converting 3D models to Sprites
- Scripting in Blender
- Creating a Model in Sketchup
- Colouring and Animating in Blender
- Animation using Dope Sheet, Keyframes and Scale Transformation in Blender
- Template
- Testing
- Terrain
- Terrain Generation
- Resource Trees
- Main Menu, Chat, options
- Main Menu V2, Options V2, Sound
- Damage Trees
- Projectiles
- Enemy User Testing
- Tree planting, inventory GUI, resources, portals
- Caveman Character
- Debug Mode Menu
- Tree learning, Attack Trees, Main Menu Tutorial Resources Styling
- Revamped Resource Trees
- Squirrel User Testing
- Final evaluation
- Project Structure
- Git Workflow
- GUI
- Worlds
- Entity Directions
- Resources
- Inventory
- AbstractEntities
- BasicProperties
- MortalEntity
- ProgressBarEntity
- Multiplayer
- Trees
- TimeEvent
- Game Time
- Animations
- Enemies
- Waves
- Player
- Projectiles
- Effect
- Particles
- Path Manager
- Sounds
- Debug 'God' Mode
- 2D Collision
- Box3D {depreciated}
- Render3D
- Cheat Codes