• How do I project an entity forward and set the velocity back the opposite direction?
    3 replies, posted
Basically I just want to throw something out, and have it come back after a bit. Here's what i used: [lua] function ENT:Throw() local phys = self:GetPhysicsObject() if IsValid(phys) && IsValid(self:GetOwner()) then phys:ApplyForceCenter(self:GetOwner():GetAimVector() * self.Speed) end end function ENT:Return() local phys = self:GetPhysicsObject() if IsValid(phys) then phys:SetVelocity(Vector(0,0,0)) phys:ApplyForceCenter( self:LocalToWorld(self:GetOwner():GetAimVector()) * self.Speed ) end end [/lua] [editline]26th August 2013[/editline] The throw works, but the return isn't.
bump
"Doesn't work" isn't very descriptive.
Why are you converting it into local coordinates? And why are you basing it on the user's aimvector? If you want the ball to return it should be [CODE] function ENT:Return() local phys = self:GetPhysicsObject() if IsValid(phys) then phys:SetVelocity(Vector(0,0,0)) local direction = self:GetOwner():EyePos() - self:GetPos() direction:Normalize() phys:ApplyForceCenter( direction * self.Speed ) end end[/CODE] This could work, not entirely sure though syl0r
Sorry, you need to Log In to post a reply to this thread.