Skip navigation
Another game dev pop quiz!
0:00 / 0:27

Another game dev pop quiz!

sleitnick

39K followers

Visit on X
182 likesDownloadOriginal post

12,689 views #RobloxDev

Another game dev pop quiz! I want to move a block forward until it hits the closest surface in front of it without clipping. Blockcasting can be used. But on Roblox, the result gives you a single point of contact (yellow dot). How do you solve for the green dot? #RobloxDev

11 Comments

Comments from the original post on X (Twitter)

  • Evelyn's profile picture

    @CosRBX

    I would say something like: OriginCFrame * CFrame\.new(0, 0, -(ray.Distance - plane.Size.Z)); Through a Blockcast that replicates the size of the block itself!

    9 likes

  • RedDeer.Games's profile picture

    @RedDeer_Games

    Customise the colours yourself or simply connect the Joy-Cons ! Head to ➡️ for more details about #AAAClock ! #indiedev #indiegame #IndieGameDev #nintendo #OLED #switchOLED

    464 likes

  • Kohl's profile picture

    @ColRealPro

    finalposition = startpos + direction * result.Distance can't test this but this would work right?

    6 likes

  • sleitnick's profile picture

    @sleitnick

    The result is the yellow dot, so that would end up clipping the cube through the part ahead of it by a little bit

    1 like

  • Peter McNeill's profile picture

    @MrChickenRocket

    What's the green dot? If the block was at the yellow dot would it be the center of the face of the cube? In which case it should be: origin + ray.Unit * hitResults.Distance

    4 likes

  • sleitnick's profile picture

    @sleitnick

    Maybe better worded: Solve for the black plane so that it doesn't clip into the surface in front of it. The yellow dot is the result from the blockcast; green is the "solved" reprojection that the black plane is on

    3 likes

  • Rory “Computer wizard”'s profile picture

    @roryhibbler1

    I'm surprised that the engine returns only the point of contact from the block cast and not also the length of the vector that causes contact. You're basically asking to map the yellow point to a point on the surface of the cube. Min cos distance a grid of cube's surface points?

    4 likes

  • sleitnick's profile picture

    @sleitnick

    Here's the fun part that @ColRealPro showed: The Distance property of RaycastResult will give you the proper distance to the green dot. But the Position property will give you the yellow dot. This is nice b/c you get both the contact point & the correct distance to project it.

    9 likes

  • Jimeyy's profile picture

    @Idk747462759

    Make the greendot’s CFrame the lookvector of the cube * the block cast distance?

    2 likes

  • Simbuilder's profile picture

    @Simbuilder

    Use the surface normal for orientation, for the distance use ray casting.

    2 likes

  • EverDaleTop's profile picture

    @EverDaleTop

    This is the kind of stuff i suck at, i am only good at the logic part of coding, not the math part

    2 likes