Hey there devs.
I am working on a rail system which i have been making a few threads about recently. What i am trying to get it to do right now, is detect irregular or sharp curves and deny the player from placing them.
The problem is that i cant seem to get it to work. I have tried multiple ways to do this. Right now i am trying to check if the turn that the track makes is more than 90 degrees, and if so, deny the player from placing it. But when it becomes very sharp, it believes that it is less than a 90 degree angle?
i was previously iterating through the track in increments, and checking if any point in the rail was turning too quickly, but that wasn’t working either.
Here is an example of how it believes that sharp turns are less than 90 degrees:
https://gyazo.com/1f146dea04811a02412888222b9ca6c8
Here is my current relevant code:
local fa, ba = b:Get(0+(0.1/lengt)), b:Get(0)
local fb, bb = b:Get(1), b:Get(1-(0.1/lengt))
local ac, bc = CFrame.new((fa+ba)/2, fa), CFrame.new((fb+bb)/2, fb)
local fac = ac.LookVector
local vec = (bc.Position - ac.Position).unit
angl = math.acos(math.max(-1, math.min(1, fac:Dot(vec))))*100
if angl > 90 then
toosharp = true
else
toosharp = false
end
:Get() just takes a value from 0 to 1 and gets the position at that percentage of the curve.
How can i stop it from allowing that sharp curve, when it is more than 90 degrees?
Thank you for any help,
- Mezza