The collision spatial is a component that manages an entities physics. There is a global physics manager in the game engine that controls things like world gravity and this component is automatically registered to that manager when it is added to an entity. In GameBuilder Studio (GBS) all entities need to have a spatial on them. It handles things like position and rotation and in this case collision shapes, physics properties like friction and bounciness. If you don't want an entity to be solved by the physics engine you can always use a Basic Spatial component instead.
Both the Basic and Collision spatial are made to control a renderer. They control the renderer's position, rotation, and size using Property References internally.
Collision Shape Debug Display
In the editor when you create a renderer you may notice a dark orange outline around the image. This is the debug display or outline of the collision shape of the collision spatial. You can toggle this debug display on and off using the "Toggle Collision Shape Visibility" icon on the toolbar to the right.
Collision Shape Editor
The collision shape editor allows you to preview the collision shapes that are on the collision spatial. You can draw a rectangle shape, circle shape, or auto trace the image in the preview area. In the future you will also be able to draw points individually and manipulate those points.
**Note: If you want to delete a shape, just select it and hit the delete key. However every collision spatial must have at least one collision shape defined.
Collision Shape Properties
All collision shapes need to have either a pre-defined global physics material or custom physics properties applied to it. You can find the global material settings in the settings window of GBS.
- Density - controls the density of the shape
- Friction - is a force which causes the motion between two surfaces / shapes to be reduced.
- Rolling Friction - is a force which causes the motion between two surfaces / shapes to be reduced during rotation.
- Bounciness - controls how much a shape will bounce off of another one.
- Is Sensor - turns the collision shape into a trigger so that the shape still sends collision notifications but does not change the position of the spatial.
If you have multiple shapes on a collision spatial and you change the properties on one shape you can apply those properties to all the shapes by clicking the "Apply To All Shapes" button.
Global Physics Materials
Toward the top of the editor there is an icon with some tools, that is the settings window. Open that window and select the Engine tab and scroll down. You will find the material manager where you can define global materials that you can apply to any physics spatial in your game. This is a great way to speed up the process of defining properties for a collision shape. As you can see the there are a number of pre-defined real world materials that come pre-loaded with the GameBuilder engine.
Entities can have multiple renderers and spatials. It is important to select which renderer is controlled by the spatial so that your renderer shows up in the right place during physics simulations. Un-checking the "Can Move" checkbox will lock the spatial into position during physics simulations. However if the position property is changed manually the spatial will still move to the new position. Same goes for the "Can Rotate" checkbox. The "Continuously Collide" check box will cause the spatial to be evaluated more frequently for every tick of the game. This is normally used for bullet type objects that move at a high rate of speed or velocity.
**Note: Renderers can be positioned manually without a spatial by changing the position property directly.
Physics Body Types
There are a number of different body types you can choose from. The Simulated (DYNAMIC) type is the default setting for collision spatials that need to fully interact with the physics world in your game. This includes gravity, impulses, constraints, etc. Changing the body type to Non-Simulated (KINETIC) will cause the spatial to ignore physics forces but still respond to collisions with other spatials.
Every spatial in GameBuilder Studio has a property to define tags or object types that describe what type of object a spatial is. The collision spatial also has a collides with type property. This is used to not only identify what type of object the spatial is but also for collision filtering. If you want to have a character in your game that only collides with objects of type floor and type enemy then you can define those different object types in the global settings window and assign the types to their respective spatial.