How would I have an entity target a player? I wanted to have it find any player/prop (doesnt target the person who spawned it) and hit them. (I remember a swep like this, but I cant find it :crying: )
Do you mean an NPC, a prop, or what? It depends on what you’re trying to do. Just “an entity” isn’t that helpful.
A prop, sorry I wasn’t clear enough
How would I use that to my advantage? Would I just set the vector to the targets vector? I do not understand.
(also how do I get the vector of players?)
[lua]pl:GetPos( )[/lua]As for the direction to apply force, because the vector is relative to the entity you’re pushing, use the following formula.
[lua]( vector1 - vector2 ) * force[/lua] vector1 being the target’s position, vector2 being the position of the prop/entity that you’re pushing and force being self-explanatory. Here is an example, it makes every prop on the map love you. [lua]
local ipairs = ipairs
local ents = ents
local pl = player.GetAll( )[ 1 ]
hook.Add( “Tick”, “”, function( )
for _, ent in ipairs( ents.FindByClass( “prop_physics” ) ) do
local vec = ( pl:GetPos( ) - ent:GetPos( ) ) * 50 local phys = ent:GetPhysicsObject( ) if ( phys:IsValid( ) ) then phys:ApplyForceCenter( vec ) //phys:ApplyForceOffset( vec, Vector(0,0,0) ) end end
I dont mean to bump this, I understood it, but How exactly to I add a hook like the one you put above into a function :downs:
(feel free to rate me dumb)
Here’s how to hook a function to an event :
And a list of all events you can hook to :