As of late 2021, we are in the process of updating Stencylpedia and fixing up outdated & broken content. Thanks for your patience!

60,411

Views

Beginner

Level

13

Comments

Setting Tile Collision Shapes

by Jon (Updated on 2015-10-11)


Note: If you're coming here from the Tiles and Tilesets article, read on. If you found this through a search, we urge you to read the main Tiles article first.

Contents

  • Introduction
  • Setting the Collision Shape
  • Custom Collision Shapes
  • Boxes
  • Polygons

Introduction

Tiles can take on more than just square shapes or blank areas. You can define their collision shapes are non-square boxes, slopes (triangles) or even arbitrary polygons.

Setting the Collision Shape

Suppose that we want to set the collision shape for the tile selected below. It's a sloped tile at about a 60 degree grade.

60-degree-tile-selected

  1. To set the collision shape, go over to the Collision Bounds window, scroll using the scroll bars to find the shape you need, and click on it.

    Set collision shape to a 60 degree triangle

    Tip: You can edit the collision shapes for multiple tiles at a time if you select multiple tiles in the left (tiles) pane. You can do this by clicking and dragging to expand your selection rectangle.

  2. Save your Tileset to confirm the changes.

    Tip: If you've placed a tile inside a scene and change its collision bounds, you'll need to open that scene and save it to make the change get reflected.

Custom Collision Shapes

Sometimes you will need a custom collision shape for a tile that isn't reflected in any of the standard shapes we provide.

If this is the case, you can define a Custom Collision Shape by clicking on the + button. You can create either a Box or a Polygon.

Box Shapes

X and Y dictate the relative position of the box, in case you want it to be shifted off the origin (0,0).

All values are in percentages (0 - 100 inclusive). We do this, so that you don't have to worry about how big the tiles are.

Creating a collision box

Polygon Shapes

Create a Polygon by defining points and setting their x,y values, either through the table or through drag and drop. A polygon must have 3 or more points but no more than 12.

Note: Define points in counter-clockwise order. If you don't, the engine may crash and warn you about a polygon having negative area.

Creating a polygonal collision shape

Gotcha: Only convex polygons are supported. Do not enter in a concave polygon such as an "L" shape. Instead, use an actor instead or split the tile into two or more separate tiles that you place on top of each other.

Print Article Edit Article How to Edit an Article
Disclaimer: Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!

13 Comments

Zemotts9
While I can set walls to box collision and floors to none when setting diagonal walls to the half block of that kind (corner to diagonal corner) the collision does not work properly. Does anybody know how to fix this issue?
0 3 months, 2 days ago
Jon
Split it into two tiles and super-impose them on top of each other. Easier solution is to do this as an actor instead.
0 9 years, 6 days ago
jaschmehl
Same question as gogisadj - explain how to do this: "If at all possible, break up concave polygon into 2 or more convex polygons instead."
3 10 years, 1 month ago
gogisadj
So, how do you give a tile multiple collision shapes?
4 10 years, 1 month ago
Hairball
I had some of the problems people have above. My tileset that I used had the 'floor' tiles (ie tiles you should be able to walk on) set to collide. I had to turn them off in the tileset to make my character able to collide with everything else. What was happening is that since ALL my tiles had collision boxes, the game was making one giant collision box (that I started inside). Since I was inside it already I wasn't colliding.

Now I'm having trouble though. I have a tile that I want to be half a box tall. In other words, the graphic only takes up half the tile, so I should be able to walk in the other half. For some reason, my actor's head still bumps up against the edge of the tile even though I've made a box that's way smaller than that.

0 10 years, 4 months ago
Jon
Correct. I've called that solution at more more explicitly at the end of the article.
0 10 years, 8 months ago
InnerSol
Re: Tinycyborg's issue (creating L shaped walls) - you could use two boxes instead of a convex polygon.
1 10 years, 9 months ago
esotericbyte
I am working with the example created in the crash courses to evaluate Stencyl.

The provided tiles I used have a square collision shape. I added some platforms and lowered the gravity. You can jump to them and they usually act as you'd expect.

Unfortunately It's possible for the player actor to be trapped in the tiles that should be
solid and there does not seem to be a way to escape.
What conditions do tiles not work and why?
I am thinking maybe they need to be smaller than the actor or something like that.




0 11 years, 9 months ago
tinycyborg
Any plans in the future to resolve the convex polygons issue? I am making a top down game and have L shaped "walls" that are bugging out because I am using Convex Polygons...
0 11 years, 11 months ago
Valeriana
Same problem here, but only with the rpg style scenes. To the platformers i dont have the problem

0 12 years, 1 week ago

Sign In to Comment