So, I'm trying to make a can entity spawn and then be thrown forward.
I tried using SetVelocity(self.Owner:GetForward() * 200) but that didn't work...
Current code:
[code]
local canPickUpThatCan = 1
function SWEP:SecondaryAttack()
if canPickUpThatCan == 1 then
local soundnumber = math.Round(math.random(1,3))
canPickUpThatCan = 0
timer.Simple(3, function() canPickUpThatCan = 1 end )
if soundnumber == 1 then
self.Weapon:EmitSound("npc/metropolice/vo/pickupthecan1.wav")
elseif soundnumber == 2 then
self.Weapon:EmitSound("npc/metropolice/vo/pickupthecan2.wav")
else
self.Weapon:EmitSound("npc/metropolice/vo/pickupthecan3.wav")
end
end
end
[/code]
The can code would look something like this, but I deleted it :( ...
[code]
local canEnt = ents.Create("prop_physics")
canEnt:SetModel(model path)
canEnt:SetPos(self.Owner:EyePos())
canEnt:Spawn()
[/code]
Not related to your issue but you can make canPickUpThatCan a boolean instead of comparing it to 0 and 1 each time
That's odd, the velocity thing seems to work for me when I try applying it to the player... have you made sure you're setting the velocity AFTER spawning the can? Also, you could try doing GetPhysicsObject on the can and then applying the velocity to that
[editline]15th February 2016[/editline]
I think I was right about the physics object thing- try this:
[CODE]
local canEnt = ents.Create("prop_physics")
canEnt:SetModel(model path)
canEnt:SetPos(self.Owner:EyePos())
canEnt:Spawn()
canEnt:GetPhysicsObject():SetVelocity(self.Owner:GetForward() * 200) -- you might want to make that number bigger
[/CODE]
Seems to work for me
[QUOTE=MPan1;49745206]That's odd, the velocity thing seems to work for me when I try applying it to the player... have you made sure you're setting the velocity AFTER spawning the can? Also, you could try doing GetPhysicsObject on the can and then applying the velocity to that
[editline]15th February 2016[/editline]
I think I was right about the physics object thing- try this:
[CODE]
local canEnt = ents.Create("prop_physics")
canEnt:SetModel(model path)
canEnt:SetPos(self.Owner:EyePos())
canEnt:Spawn()
canEnt:GetPhysicsObject():SetVelocity(self.Owner:GetForward() * 200) -- you might want to make that number bigger
[/CODE]
Seems to work for me[/QUOTE]
Ahhh. This works! Thank you so much!
Sorry, you need to Log In to post a reply to this thread.