Finally after organizing the Boids module, I move on to trying LinearVelocity just after using BulkMoveTo, that’s because I want to have collisions for boids when bumping an object.
But then I come to this problem: Boids are now falling off and scattered over on the grounds. They don’t ever fly anymore… I checked their LinearVelocity velocity property Y and it was at minus no matter what. No problem with this when I use the ordinary CFrame method. How do I fix this problem? I need to know better about LinearVelocity!
a snippet from create function:
if self.useLinearVelocity then
self.boid.Anchored = false
self.boid.CanCollide = true
self.boid.Massless = true
local _attachment = Instance.new("Attachment")
_attachment.Parent = self.boid
self.attachment = _attachment
local _linearVelocity = Instance.new("LinearVelocity")
_linearVelocity.Attachment0 = _attachment
_linearVelocity.MaxForce = math.huge
_linearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
_linearVelocity.VectorVelocity = Vector3.yAxis
_linearVelocity.Parent = self.boid
self.linearVelocity = _linearVelocity
end
a snippet from update function:
self.Acceleration =
alignment * self.factor.alignment
+ cohesion * self.factor.cohesion
+ separation * self.factor.separation
+ targetVector * self.factor.target
+ repulsion * self.factor.repulsion
+ obstacle_avoidance * self.factor.avoidance
+ velAvoidBounds * self.factor.outside_cage_push
--print(self.n)
local accMagnitude = self.Acceleration.Magnitude
if accMagnitude > 0 and accMagnitude == accMagnitude then
self.boid.Velocity += self.Acceleration * dt * 12
end
self.boid.Velocity = BoidHelpers.clamp_magnitude(self.boid.Velocity,self.speed.Min,self.speed.Max)
local positionFinal = self.boid.Position + self.boid.Velocity*dt * 4
if self.nUpdate == 0 then
self.curOcTree:ChangeNodePosition(self.node,positionFinal)
end
if dt*self.factor.rotation_lerp < 1 then
self.VelocityLerp = BoidHelpers.LerpVector(self.VelocityLerp,self.boid.Velocity.Unit,dt*self.factor.rotation_lerp)
else
self.VelocityLerp = self.boid.Velocity.Unit
end
if self.useLinearVelocity then
self.linearVelocity.VectorVelocity = self.boid.Velocity
self.boid.CFrame = CFrame.new(self.boid.Position,self.boid.Position + self.VelocityLerp) * lookAngle
--self.attachment.CFrame = CFrame.new(self.attachment.Position,self.attachment.Position + self.VelocityLerp) * lookAngle
else
self.CFrameCollection[self.index] = CFrame.new(positionFinal,positionFinal + self.VelocityLerp) * lookAngle
end
Boids before using LinearVelocity (BulkMoveTo method)
Boids after using LinearVelocity
Please help me on this, thanks!!