In short form, I'm trying to make it so enemies dont just directly walk the track in my TD game but have some diffrentiation to it. The problem im facing is that, say a enemy starts at the start of the green line in my image, and wants to go to the curve. I have to figure out WHERE the enemy intersects.
So, what formula do I have to use to get that point? Basically, I have previouswaypoint, and waypoint (variables) which are practically the only two things I have. They are just parts that point to the next one. Heres a code snippet I tried but i didtn get anywhere with it.
local rootPart = clone.HumanoidRootPart
local heightOffset = Vector3.new(0, (-0.5) + clone:GetAttribute("Height"), 0)
local currentPos = rootPart.Position - heightOffset
-- my old flawed code which only works on some bends
local discrepancy = clone:GetAttribute("Discrepancy") -- basically the offset on the x axis
local targetPos = (waypoint:GetPivot()*CFrame.new(discrepancy,0,-discrepancy)).Position
local fromPos = (previouswaypoint:GetPivot()*CFrame.new(discrepancy,0,-discrepancy)).Position
** You are now Level 2! **