The ULTIMATE guide to smooth collisions

Heyo hopyos, hope you are having a great day!

Have you ever wanted to make a plataformer but struggled with coding the collisions? Or, let’s say, wanted to code a pool game but never knew how to make the balls collide and react?

Well! You’ve come to the right place! Here I will teach you the basics about smooth collisions, the uses, and the different types!

Square collisions

Ok, so you wanna do square collisions

Let’s say your character moves because of the vertical and horizontal velocities, but the character is fixed at the middle of the screen, making background objects being the actual stuff that moves

We would make a rule that sets where is the player X or Y according to our map, and we would subtract that values to the map’s objects, like this

In this example, the variable Scroll X determines where my character is, and the variable (self) X defines the blocks position in relation to the map

So, now that we know those values, let’s use them to create a collision with the character!

We can make either one only rule for collisions, or 2 rules, or 4 rules

In this case we will do 2

So what we will do first, is to check if the player is colliding near any side of the block, the code would look like this:
When Absolute value (charafter) X position - (self) X position < (self) Width/2 + (character) Width/2

NOTE: This rule goes on the blocks’ sprite, not on the character one

This rule measures how far a block is from the character, and if the character is inside a certain area surrounding the square, the function will trigger

To make the character stop there, just put this code inside the rule:
Check once if (character) Y position - (self) Y position < (self) Height/2 + (character) Height/2
Check once if (character) X position > (self) X position
Set (character) horizontal velocity to 0
Set Scroll X to (self) X*(self) width - (self) width/-2
Set (character) horizontal velocity to 0
Set Scroll X to (self) X*(self) width - (self) width/2

now we have done the side collisions! This will make the character stop when it is touching the side of the object, this same rule can be adapted to when the character is on a block, we will see the adaptations right now

The following code goes inside this rule:
When Absolute value (charafter) Y position - (self) Y position < (self) Height/2 + (character) Height/2

Check once if (character) X position - (self) X position < (self) Width/2 + (character) Width/2
Check once if (character) Y position > (self) Y position
Set (character) Vertical velocity to 0
Set (Character) Y to (self) Y + (self)Height/2
Set (character) vertical velocity to 0
Set (Character) Y to (self) Y + (self)Height/-2

It’s basically the same; we just change the x values for y values and vice versa

So now that we have done our square collisions

We can advance to circular ones, even though they are hard to use on a platformer context, I’ll teach you how to get them and how they work!

Circular collisions

This collisions need a bit less of code, since they can be resumed in just one rule, but it’s hard to make it so a character bumps into them, so why not use them instead, for making a score?

The rule is pretty simple, I’ll leave it here:
when absolute value √([{character} X position - {self} X position]^2 + [{character} Y position - {self} Y position]^2<(self) Width/2

This rule works the following way, it calculates the distance of an object to another and checks if that object is within a certain radius

(This collisions can be observed in my summer team’s game, Beach Mayhem, at the treasure hunt place)

Anyways, this is all you need to know to code collisions! This concept was inspired by @Nobody

Hope it’s helpful! @ omtl


No I clicked on accident



want me to delete then you can delete the topic?

Sigh I’m.p not done yet…

1 Like

Ok anyways I’m pretty much done with side collisions

1 Like



Very useful for me.
My platformer is wonky lo
Finish it


wow my thinking was close lol, I wasn’t doing absolute value and that messed it up

Can a leader please edit the op and change the last thing to this?


Or type the rest and tell a lead to edit it in
Sigh too late

1 Like

Yeah but I will do that separately

That post above was an edit, I’ll do the rest now


I’ve always had trouble with collisions. This has helped me a lot.


Thanks! @TheCMStudios


Hey @TheCMStudios, I’m done with the topic, could you please edit the op? Just delete everything and paste this

Thanks in advance m8!


Oof the omtl tag in the OP didn’t work so @omtl check the op!

This might be a helpful topic!


I completed the tag and did an edit to cancel it in case future edits are made


Oooh, smooth! Thanks for sharing this!


Love the tutorial!

1 Like

I thought I have this exact thing in Tip of the Week, but nice job regardless!


oo nice topic!