Move a object to a player

I need a piece of code that will force an phy object to a nearby player?
Its something like this?



    local phys = self.Entity:GetPhysicsObject()
 
    if(phys:IsValid()) then
        phys:ApplyForceOffset( Vector( 0, 0, 500 ), Vector( 0, 0, 0) )


But that just moves it up.
How do I get it to push near to a player?

[lua]phys:ApplyForceOffset( self.Entity:GetPos() - ply:GetPos(), self.Entity:GetPos() )[/lua]

Not sure if that’s entirely right, but try that.

PLY needing to be defined?

Of course, how would it know which player/entity otherwise?

Testing now…

[editline]06:21PM[/editline]

Ok what is wrong with this code i just c&p’d It from outher bits of my mates lib of code



function ENT:Think()


    local radius = 250
    local ents = ents.FindInSphere( self:GetPos(), radius )
    local function ply_explode( ply )
        if ply and ply:Alive() then
            local vPoint = ply:GetPos()
	    self.Entity:ApplyForceOffset( self.Entity:GetPos() - ply:GetPos(), self.Entity:GetPos() )  
	end


end


Here. (tested)

[lua]
function ENT:Think()

    for k, v in pairs( ents.FindInSphere( self.Entity:GetPos(), 250 ) ) do

            if ( v:IsPlayer() and v:IsValid() ) then
			
    self.Dir = v:GetPos() - self.Entity:GetPos()
				
                self.Entity:GetPhysicsObject():SetVelocity( self.Dir:Normalize() * 500 )

            end

    end

end
[/lua]

:slight_smile: