Pushing SWEP

Hey there!

I’ve been trying to create a SWEP that will allow me to push or pull and object towards the user when the user is aiming at something, and if he isn’t, push or pull in the direction the user is facing. So far, I’ve come up with is:

[lua]
function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) or (self.Weapon:Clip1() < 5) then return end

self.Owner:SetVelocity(self.Owner:GetVelocity() + self.Owner:GetAimVector())
self:TakePrimaryAmmo(5) 

end [/lua]

I’ve tested that, and, if I’m on the ground, nothing happens, but if I’m in the air, it makes me go off in odd directions. Can anyone please put me in the right direction?

Thanks in advance!

you are trying to set a doubled velocity to yourself in the direction your looking at.

what i found out from the code.

what you need to do:

  1. define your pull/pushables
  2. apply negative velocity to the object in your AimVector
  3. add secondary attack to apply velocity forwards on the object

i can try to make this once i get home.

GetAimVector is normalized, the most you’d be applying would be 1, 1, 1

Do GetAimVector() * 5000 or something and remove GetVelocity

1, 1, 1 isn’t a normalized vector.

I feel dumb then

The length of a (1, 1, 1) vector is sqrt(3). Normalized vectors have a length of 1.

Yep, my mistake