OK. Starting from the top. Here’s what I have:
[lua]GRAV = {}
GRAV.Centers = { { point = Vector(100,100,1000), strength = 1}, { point = Vector(500,100,700), strength = 1}, { point = Vector( 200, 300, 1200) , strength = 1 } }
GRAV.Speed = 0.3
GRAV.Radius = 2500
if SERVER then
function GRAV:Initialize()
for _,v in pairs( ents.GetAll() ) do
local phys = v:GetPhysicsObject()
if IsValid( phys ) then
phys:Wake()
v:SetGravity( 0.00000001 )
end
end
hook.Add("Think","GRAVDoGravity",function()
for _,v in pairs( ents.GetAll() ) do
local phys,dir = v:GetPhysicsObject()
if not v:IsPlayer() and IsValid( phys ) then
local valid_points = {}
local dist
for _,grav in pairs(self.Centers) do
if v:GetPos():Distance( grav.point ) <= self.Radius * grav.strength then table.insert(valid_points,grav) end
end
local vel = Vector(0,0,0)
for _,grav in pairs( valid_points ) do
dist = v:GetPos():Distance( grav.point )
vel = vel + ( grav.point - v:GetPos() - phys:GetVelocity() ) * self.Speed * math.Clamp( ( self.Radius * grav.strength - dist ) / ( self.Radius * grav.strength ) + 0.2, 0, 1 ) * grav.strength
debugoverlay.Cross( grav.point, 15, 0.05, color_white, true )
//debugoverlay.Sphere( grav.point, self.Radius * grav.strength, 0.03, color_white, false )
end
phys:SetVelocity( vel )
end
end
end)
end
GRAV:Initialize()
end[/lua]
When I had two points with a strength of 2 and 3 respectively, it worked fine. The ball would go closer to one point than the other.
However, with three points if I add too much to the strength or set GRAV.Speed to 0.5 like it used to be the ball begins to spazz out. What’s the cause of this and how would I fix it? (I’m not really familiar with this kind of stuff…)