I’ve create a seek steering but im trying to predict its location on the path and still steer that way but within a radius.
Here is my code, i cant figure out why it doesn’t wanna work correctly. my math is horrible hopefully someone can help me out
[[---------------------------------------------------------------------------------------------------------------------------------]]
local max_velocity = 50
local boid = game.Workspace.Test
local BodyVelocity = boid.BodyVelocity
–local target = game.Workspace.Target
local start = game.Workspace.A.Position
local end_ = game.Workspace.B.Position
function steer(target)
local desired_velocity = (target-boid.Position).unit * max_velocity
local newSteer = desired_velocity - boid.Velocity
return newSteer
end
function getNormalPoint(p, a, b)
local ap = (p - a);
local ab = (b - a)
ab = ab.unit
ab = ab * ap:Dot(ab)
local normalPoint = (a + ab);
return normalPoint
end
game:GetService(“RunService”).Stepped:connect(function()
local predictLoc = BodyVelocity.Velocity * 2
–local predictLoc = (BodyVelocity.Velocity + predict)
local a = start
local b = end_
local normalPoint = getNormalPoint(predictLoc, a, b);
local dir = (b - a).unit * 10
local target = (normalPoint + dir);
local distance = (normalPoint - predictLoc).Magnitude
if (distance > 15) then
BodyVelocity.Velocity = steer(target);
end
end)
Here is a site i am using
https://natureofcode.com/book/chapter-6-autonomous-agents/#chapter06_section8