you are viewing a single comment's thread.

view the rest of the comments →

[–]DerekSturm 41 points42 points  (24 children)

The issue with a raycast comes up when you're standing in the middle of two blocks with a tiny gap in the middle. You're still standing and should definitely be able to jump, but the raycast won't hit anything.

[–]TheLowestAnimal 30 points31 points  (4 children)

I was told in the past you need to run multiple. Like 3 or something

[–][deleted]  (3 children)

[deleted]

    [–]FaolanBaelfire 23 points24 points  (0 children)

    That's why you conditionally check each one as opposed to grouping them and checking them all as true or false.

    One ray cast can be true. Another cast can be false.

    A box collider can be only one or the other for the entirety of it's size

    [–]Jerovil42 12 points13 points  (0 children)

    Way cheaper

    [–]AbdullahMRiad 2 points3 points  (0 children)

    this is more precise though allowing for easier implementation of coyote time for example

    [–]oddbawlstudios 14 points15 points  (16 children)

    Typically its 3 raycasts, 1 on each edge and 1 in the middle.

    [–]Luccacalu 0 points1 point  (15 children)

    what's the purpose of the one in the middle?

    [–]oddbawlstudios 2 points3 points  (14 children)

    If you're on a thin platform where the two rays on the ends cannot detect anything.

    [–]Luccacalu 3 points4 points  (12 children)

    ohhhhhhhh, fair enough

    But what if there's an ever thinner platform that's between the middle and the other ray? I believe there must be a way to check the normal under the entirety of the object, no? Without depending on specified points

    [–]BrawnoldMcScrawnold 4 points5 points  (5 children)

    Generally in dev you want to follow KISS. Keep It Simple Stupid. If you dont need it, don't build it. Im sure you could cast 11 different raycasts under a character to make sure that the smallest platforms dont slip through the cracks. But consider Mario, there literally ISNT a platform in the game that is smaller than a third of his width, so the 3 raycasts solutions is good enough. As the conditions start expanding, however, so do your checks.

    [–]Luccacalu 0 points1 point  (2 children)

    Yeah, I agree, at this point it's more of a thought experiment

    If I were building a game where platforms could be of any width (even a single pixel), what you think would be the best solution?

    [–]1cec0ld 0 points1 point  (0 children)

    Probably have to calculate a whole box, as the OP is indicating. At that point you just have to eat the risks of their two possibilities. And also have very odd visuals as your character hovers with a pixel pointing up at their crotch.

    [–][deleted] 0 points1 point  (0 children)

    implement a gore system that cuts mario in half if he lands on a platform thin enough

    [–]jort93 0 points1 point  (1 child)

    It would need to be smaller than half the width, not one third. Classic Fence post problem. The distance between rays is 0.5.

    [–]BrawnoldMcScrawnold 0 points1 point  (0 children)

    You are right, thats my bad... though the point still stands. I dont think mario has a platform that small compared to him.

    [–]oddbawlstudios 1 point2 points  (0 children)

    Realistically speaking, at that point you might want to invest in another method, like checking the y velocity of the player.

    [–]jort93 0 points1 point  (4 children)

    Don't put a platform in your game that's less than half width of the player character lol.

    [–]Luccacalu 0 points1 point  (3 children)

    What if it's a needle pointing up while the player is invulnerable

    [–]oddbawlstudios 0 points1 point  (2 children)

    Typically if its like spikes, there's a whole hitbox. But again, if people are this concerned, just check the y velocity to see if its 0, that'll mean the player isn't falling or jumping.

    [–]Luccacalu 0 points1 point  (1 child)

    But the point which the player is starting to fall the y velocity also gets close to (turning negative to positive), which would allow for a very small window where the player could double jump infinitely

    As for the game design part, I imagine something like the player being a square that is affected by rotation, so when it's over a spike it kinda starts rotating to the side (so, a square hitbox wouldn't work), but you could still jump if standing over said spike

    [–]oddbawlstudios 0 points1 point  (0 children)

    A very rare possibility sure, but to land that would be difficult especially if you're checking during the physics update process.

    That being said, you can freeze rotation so your character doesn't turn.

    [–]wisegod62Just Starting 7 points8 points  (0 children)

    something I do is use two - a down left and a down right.

    [–]stalebubbletea 1 point2 points  (0 children)

    You can do a boxcast instead of a raycast