How would I create a grenade and set a velocity and position?

Hello. One of the key features I plan on implementing into a SWEP I’m making is it’s ability to shoot SMG grenades(the entity name of this is grenade_ar2) for it’s secondary fire. I’ve tried a lot of things, but I can’t get it to work. What ends up happening is it just flies off depending on where I’m aiming(it seems to direct it to the spot I spawned at, probably something to do with the vector commands I used, but I’m not here to get a code fixed). I have no idea what I’ve been doing wrong; a little help, please?

-snip-
didn’t read.

WEAPON/SecondaryAttack

ents.Create

Entity:SetVelocity

Player:GetAimVector

Haha, I said that I’m not here to get a code fixed. I need an idea as to what to use.

[editline]25th April 2015[/editline]

I tried all of those. However, I didn’t use them in this specific order, let me try now. I didn’t rely on self.Owner:GetAimVector, as it seemed to(when I used it) make the grenade fly to my spawn point, not which way I was looking. It might now be GetAimVector, though it might have been.

Maybe it’s ply:GetShootPos()?

I don’t see how the EyePos of the player would help.

something like this?


function SWEP:ThrowFrag(  )

	local frag = ents.Create( "grenade_ar2" )
	if ( !IsValid( frag ) ) then return end

	frag:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 16 ) )
	frag:SetAngles( self.Owner:EyeAngles() )
	frag:Spawn()

	local phys = frag:GetPhysicsObject()
	if ( !IsValid( phys ) ) then frag:Remove() return end


	local velocity = self.Owner:GetAimVector()
	velocity = velocity * 100000
	velocity = velocity + ( VectorRand() * 10 ) -- a random element
	phys:ApplyForceCenter( velocity )

	
end

I did something similar with a SWEP that threw standard frag grenades, not sure if the physics work the same way for these grenades though.