Slope collision TEST

My two objects: “player” (this) and “test
I used @luxapodular’s tutorial to help me.

I set “hit” to a convex collision between “this” and “test

let hit = this.hits(test, {
    mode: "CONVEX",
    intersections: true, 
    overlap: false,
    offset: false
});

After doing that, I found it interesting how Wick created an array of all of the intersection points between these two objects!

hit.intersections // array of intersection points

So I used a using “try{}catch(err){}” statement to use the intersection points and know that the objects are not touching when there’s no collision.

How I used the intersection points to make slope collision:

Summary

To start with, here’s a picture with intersection points and a player and an object

I simply want the player to be ON TOP of the points to be on top of the object

Yet, what if a player is on top of intersection point A, yet walking into the object?

That’s why I pushed the object to the left of the point

If the object was on the other side of the object, of course I would need to push it that way

To know which side to push the player towards, I use the position of the intersection point in relation to the player.

And repositioning the player was done by making it’s position the same position as the point, but x value is more or less by half of the player’s width, and it’s y position was higher by half of the player’s height

And here are the results:

HTML (2.1 MB) WICK (6.0 KB)

WARNING: My code is a bit messy bc it’s supposed to be a test. Making an improved version should be easy though.

Preview:

Untitled_ Mar 7, 2021 3_14 PM

Keys:

Right, and Left arrows to move
Up arrow to jump

5 Likes

Very nice!!! Good achievement!

1 Like

I want to see that motorcycle demo… :slight_smile:

Thanks :D

Not really sure what you mean by this :motorcycle: :question:

haha, sorry… When you showed me this, what I saw was a motorcycle game with slopes…

Screen Shot 2021-03-07 at 4.43.44 PM

Screen Shot 2021-03-07 at 4.43.10 PM

2 Likes

really interesting
It should be useful to develop a method to check an object hit test against a single point
like this.hits(100, 150)
it should be a faster solution in alot of cases

1 Like

is that moto x3m??? i miss that game so much!