I am having problems with a weapon floating after it is dropped. This is for TTT. The problem is not css being mounted as it is only for one weapon and not every weapon.
The weird thing is that the weapon appears to drop correctly for the person that dropped it but it appears to float in mid-air for others.
The problem lies with the DrawWorldModel function I believe. I think for some reason it isn't invalidating/nil the owner quick enough for other players. Here is the code.
Any help or ideas would be appreciated.
[CODE]
function SWEP:DrawWorldModel( )
local hand, offset, rotate
if not IsValid( self.Owner ) then
self:DrawModel( )
return
end
if not self.Hand then
self.Hand = self.Owner:LookupAttachment( "anim_attachment_rh" )
end
hand = self.Owner:GetAttachment( self.Hand )
if not hand then
self:DrawModel( )
return
end
offset = hand.Ang:Right( ) * self.Offset.Pos.Right + hand.Ang:Forward( ) * self.Offset.Pos.Forward + hand.Ang:Up( ) * self.Offset.Pos.Up
hand.Ang:RotateAroundAxis( hand.Ang:Right( ), self.Offset.Ang.Right )
hand.Ang:RotateAroundAxis( hand.Ang:Forward( ), self.Offset.Ang.Forward )
hand.Ang:RotateAroundAxis( hand.Ang:Up( ), self.Offset.Ang.Up )
self:SetRenderOrigin( hand.Pos + offset )
self:SetRenderAngles( hand.Ang )
self:DrawModel( )
end
[/CODE]
You're only drawing the positioning for the owner, not all players.
So how do I get it to "drop" correctly for other players viewing the model when the player drops it and not just float in mid air. It drops correctly for the person who dropped it but not for anyone viewing it.
I tried messing with the DrawWorldModel because I thought the problem is in there but most of my attempts just lead to "crotch gun" syndrome. So I know this function is needed so the weapon doesn't become a crotch gun.
In your init.lua do you this? Some MoveTypes would cause it to float.
[CODE]
self:SetMoveType( MOVETYPE_VPHYSICS )
[/CODE]
Make sure if its a custom weapon that you include the .phy file. Pretty self explanatory, but thought id say it.
[QUOTE=Winter;43788687]In your init.lua do you this? Some MoveTypes would cause it to float.
[CODE]
self:SetMoveType( MOVETYPE_VPHYSICS )
[/CODE][/QUOTE]
Nope nothing like that. Should I try adding that and if so where? Make a PreDrop function?
[QUOTE=_Jacob;43788919]Make sure if its a custom weapon that you include the .phy file. Pretty self explanatory, but thought id say it.[/QUOTE]
Yep the physics file is there in resource.AddFile. It drops fine for the person who dropped it just not for others which is what is really weird about this bug.
Sorry I don't think my post applies. You're working on a weapon.
I can call Initialize... I'll try playing around with that when I get home. Hopefully it will work. Thanks.
In TTT you normally call SetMoveType for an entity of a weapon (ie something that is thrown or created from the weapon) The actual weapon entity itself doesn't need the SetMoveType set... at least for any TTT weapon SWEPS I have came across.
Hey check out this Thread, [url]http://facepunch.com/showthread.php?t=1278821[/url]
Seems like your problem, this might fix it.
That thread didn't help and adding self:SetMoveType( MOVETYPE_VPHYSICS ) to initialize didn't help... :(
[editline]4th February 2014[/editline]
This seems to work
[CODE]
function SWEP:DrawWorldModel( )
local hand, offset, rotate
local pl = self:GetOwner()
if IsValid( pl ) then
local boneIndex = pl:LookupBone( "ValveBiped.Bip01_R_Hand" )
if boneIndex then
local pos, ang = pl:GetBonePosition( boneIndex )
pos = pos + ang:Forward() * self.Offset.Pos.Forward + ang:Right() * self.Offset.Pos.Right + ang:Up() * self.Offset.Pos.Up
ang:RotateAroundAxis( ang:Up(), self.Offset.Ang.Up)
ang:RotateAroundAxis( ang:Right(), self.Offset.Ang.Right )
ang:RotateAroundAxis( ang:Forward(), self.Offset.Ang.Forward )
self:SetRenderOrigin( pos )
self:SetRenderAngles( ang )
self:DrawModel()
end
else
self:SetRenderOrigin( nil )
self:SetRenderAngles( nil )
self:DrawModel()
end
end
[/CODE]
Sorry, you need to Log In to post a reply to this thread.