Colliders (I)

(I) IMPORTANT: Understanding this section is vital to using Platformer PRO.

Character collisions in Platformer PRO are controlled by the RaycastColliders you define on your character. There are a number of colliders for each of the head, sides and feet of the character.

After you create a character by adding the Character component you can define the colliders for your character using the Collider Editor:

Resetting Colliders

Press the Reset Colliders button in order to reset your colliders back to different defaults. When you press this button you will be shown a list of options based on the configuration of your character.

 

Option

Details

Requirements

Reset to default position

Resets colliders to a box shape.

None.

Use basic sprite detection

Resets colliders to the sprite bounds.

Child with a SpriteRenderer

Use smart sprite detection

Reads the alpha channel of the sprite to guess the best places for the colliders.

Child with a SpriteRenderer that points to a readable Sprite.

Use mesh based detection

Resets colliders to the bounds of the mesh.

Child with a MeshFilter.

 

Reset collider options with a readable sprite as a child of the Character GameObject:

 

 

Reset collider options with a non-readable sprite as a child of the Character GameObject (notice the info message):

 

 

After your basic colliders are set you can use the Edit Feet, Edit Sides, and Edit head button to refine the position of your colliders.

 

Editing Colliders - Feet

 

The feet colliders push the character upwards, they are what the character ‘stands’ on. 

Remember: the colliders define raycasts, not a box collider or line. If the feet raycasts are not colliding with anything the character will fall!

Clicking Edit Feet shows edit feet scene view:


 

 

Use the handles to drag the boundaries of the characters feet.

In the inspector you will see the edit feet options:

 

Use the Add Collider button to add more colliders to the character. Each collider will be indicated with a small circle drawn along the line. Use the Remove Collider button to remove additional colliders. Because feet colliders must be evenly spaced you can only control the boundaries of the feet colliders.

More colliders will allow your character to stand on very thin platforms. You should also use more colliders (4 or 5) if you are dealing with steep slopes. You should rarely need more than 5 feet colliders. 

The Reflect changes on both sides checkbox keeps your character symmetrical. In most cases you want your character to be symmetrical but if you do have an asymmetrical character see Working with Asymmetrical Characters.

NOTE: when using tiles the size of tiles should be considered, not just the size of the platforms. If all platforms are 1 unit wide, but tiles are only 0.5f units wide, its worth ensuring your feet collider width is smaller than the tile size.

 

Editing Colliders – Sides

 

The side colliders push the character to the side: they stop it walking through walls.

Working with side colliders is similar to working with feet colliders, however you have more control over the position of the side colliders:

 

Use the handle to move the colliders and the button to add a new collider. Hold SHIFT and click the button to remove a collider.

Remember: you need to have enough side colliders such that the largest distance between any colliders on the same side is smaller than your thinnest wall or platform. This ensures the character can’t ‘pass-through’ the wall. Usually 3 or 4 is adequate.


Remember how the colliders work, they push the character to the side, if your colliders are not aligned in x your character may jerk oddly as the player pushes towards walls when falling.Press Align in X to align all of the colliders along the x-axis. Most characters should have their colliders aligned along the x-axis.

However non-aligned side-colliders can work for some characters, particularly oddly shaped or 2.5D characters. If you want to use non-aligned side colliders aim to use many side colliders to provide a smooth shape:

 

The Space Evenly button will space colliders evenly along the y-axis.

The Reflect changes on both sides checkbox keeps your character symmetrical. In most cases you want your character to be symmetrical but if you do have an asymmetrical character see Working with Asymmetrical Characters.

 

Editing Colliders – Head

 

Head colliders stop your character from jumping through the roof.

Working with head colliders is similar to working with side colliders. Instead of aligning in x and spacing in y you have options to align in y (Align Top) and space in X (Space Evenly).

Like the other colliders you must ensure the head colliders are close enough together that the character cannot passthrough a platform. 

NOTE: when using tiles the size of tiles should be considered, not just the size of the platforms. If all platforms are 1 unit wide, but tiles are only 0.5f units wide, its worth ensuring your head collider width is smaller than the tile size.

 

General Collider Configuration

 

The following guidelines will help ensure your character behaves as expected without odd pops or jerks: only break them if you are sure you know what you are doing!

  • Side colliders must be inside the bounds in y defined by the head and feet colliders (this is enforced by the editor).
  • Generally side colliders should ‘stick out’ at least a little further than the head and feet colliders.
  • Generally head and feet collider boundaries should be roughly the same: if a character falls directly down from a platform they should generally be able to jump back up without hitting their head.

 

Debugging Colliders

 You can see exactly what is going on with your colliders by pressing the Debug Collider button found on the Character inspector. In Edit Mode this shows the colliders boundaries and extents but in Play mode it shows much more:

 

 

White lines show the colliders extent with the arrows indicating direction.

Grey lines show the look ahead: this is the total distance the ray is cast. Look ahead is used for things like detecting walls or detecting the ground before pushing off of it.

Blue circles show collisions in the look ahead zone. They may be used to decide on actions but they will not affect character position.

Red circles show collisions in the colliders extent. They will affect the characters position.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk