Unions vs Raycast returning Unnormalized surface normal

Very recently I got a bug report from a user playing my game Guts & Blackpowder, and he was saying that as of the latest Roblox update he’s been experiencing issues placing down sapper buildings in places where he could before. I investigated this and found out that in the code where it checks if the surface being placed upon is flat enough, the math.acos function was returning nan. Looking further into it, I found out that the RaycastResult was returning a normal that would usually be (0, 1, 0) as (0, 1.0000001192092896, 0). I was able to reproduce this bug in an isolated place file with the specific UnionOperation that is causing this issue.

Screenshot with decomp geometry turned on:

ReproduceUnionSurfaceNormalBug.rbxl (56.2 KB)
In the place file there’s a script in workspace called “Reproduce” that does a raycast straight down onto the troublesome Union’s face, and it outputs the surface normal and then a math.acos(Vector3.yAxis:Dot(result.Normal)) which returns nan because the dot product is greater than 1.

Expected behavior

This exact place 100% used to not do this. I can easily account for this bug, but it’s annoying nonetheless. It should always return a vector with the length of exactly 1 (I know about floating point errors, but this didn’t happen before)

5 Likes

First, always clamp your acos() inputs :slight_smile:
Second, we just rolled back a flag. Let me know if that fixed it.

3 Likes

It appears to be fixed now, it’s returning (0, 1, 0)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.