GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Side-of-platform Collision... can someone tell me the best way to handle this?

Alright. I have an actor (main character) and he jumps around and lands on platforms (box actors) and runs across them etc. Some of the platforms have slight rotations to them, some do no. All the platforms come from the same prototype actor.

What I'm looking to do is have it the main character only interact with the topmost side of the platform square. That way if he has collided against the side of the platform in mid-air, he does not have the ability to jump again until he has grounded himself.



My Current Solution:

So far, I've accomplished this by creating a boolean called "grounded?" that changes to "true" if he collides with the platform and his feet are higher than the platform's Y position plus half its height.



My Ongoing Problem:

The above works for platforms that sit at a perfectly horizontal angle, but when I have the platform rotated at all, he can only be grounded on the part that is tilting upwards (naturally).

I had it so he detects the walls and can't jump when touching a wall, but then that made it so if he's touching the floor and a wall he can't jump. It just mad it worse for me.



No, I don't want to make narrow invisible platforms that I manually place to solve this. That will create more problems for me later down the road because I plan on spawning platforms and it gets convoluted. Plus, it bothers me that I can't just have my guy only interact with the topmost facing side of a single, angled actor. I know there is a geometric solution but my brain isn't strong enough to craft the equation that finds the surface at an angle.


Does anyone have a good, clean, and ideally programmatic solution to this? Does this exist anywhere? Am I even making any sense?




Best Answer

  • ammansabetammansabet Posts: 4Member
    Accepted Answer
    I figured it out. It was mathematically ridiculous, involving the pythagorean theorem, then translating the polar coordinates of the rectangle to cartesian coordinates, then using trigonometric functions to plot the four corners.

    So now, without using any invisible actors, I can have my character land on and jump off of the top side of a square actor, regardless of its rotation.

Answers

  • jn2002dkjn2002dk Posts: 102Member
    I know this isn't what you wanted but truth be told i have no idea how to handle this with math so i'm just gonna throw it out there

    Couldn't you solve most of this by making a small invisible actor at your players feet to handle the collision instead?

    That way you wont have issues down the line with spawning platforms or anything

    That's the only idea i've got, hopefully someone with better math skills than me can help with a cleaner solution
This discussion has been closed.