Set Collider in game play with triangular shaped sprite

setCollider(type, xOffset, yOffset, width/radius, height, rotationOffset)

I tried looking through past posts and was unable to find previous questions and answers about this.

I have a student wanting to use a triangular shaped object in a game similar to FlappyBird. In game play, player is quite “far” from the tip of the triangle and is called for touching since the bottom of the triangle is that wide. (stalagmites and stalactites in a cave instead of pipes like the original)

Could we use the offset (x Offset, yOffset, width/radius, etc) to make it more like a triangle?
If so, how?

I don’t believe you can but I have tried using 2 separate sprites for the left/right side of the obstacles (The bottom side is unnecessary as they are attached to the edges of the screen).

Hi @lkeil,

According to the documentation for setCollider, the collider can be a circle or a square that may be offset from the object’s center.

Please provide a link to the student’s project if you’d like one of us to take a look at it, but the documentation should be enough to get your student started in figuring out their game. (If they want to be ambitious, they can learn an early calculus lesson & realize that triangles can be approximated by several rectangles stacked together. :slight_smile: )

Hope that helps,
–Michael K.

I had thought of that solution also, but we wanted something that would take less time to correct. lol

Yes, we know about the circle and square set, but we were wondering if we can set all//any of this:

(type, xOffset, yOffset, width/radius, height, rotationOffset)

    to get the radius closer to the object's center since (for example) the sprite tapers at the bottom and isn't as wide at the bottom as the top.

Student did the easiest fix and changed sprites from stalagmites to rectangular log looking items. lol

Could there be a suggestion in’s code to add an option for triangular shapes?

Thanks for the ideas! I appreciate all the help!

Yes, you can set all of those things, but only for circles and squares. You could try separate sprites with different offsets & dimensions as another poster suggested. I invite you to submit a feature request for the ability to customize the sizes and shapes of colliders, perhaps in the animation tab.

–Michael K.

1 Like

Great ideas! Thank you so much for the help! :slight_smile:

1 Like