Hello. I am working on some melee SWEPs and have an issue: If the target is running while I am running and swinging at it then every melee attack seems to miss even though I am right next to the target with my crosshair on them. If the target is still while I am still there is no problem. This is the method I am using to determine the target and if it is in range:
[code]
local ply = self.Owner
local tr = util.TraceLine( {
start = ply:GetShootPos(),
endpos = ply:GetShootPos() + ply:GetAimVector() * 150,
filter = ply
} )
local ent = tr.Entity
if ( IsValid( ent ) && ent:IsPlayer() && ent:Team() != ply:Team() ) then
//omitted code to deal damage
self:SetNextPrimaryFire( CurTime() + self:SequenceDuration() + 1 )
else
self:SetNextPrimaryFire( CurTime() + 1 )
end
[/code]
Is there a better method that I could be using or am I doing this all wrong? My preferred result is to have every melee attack hit the target within range regardless of if moving or not. Tutorial references are also appreciated.
[url=http://wiki.garrysmod.com/page/util/TraceHull]util.TraceHull[/url] might be worth a shoot.
And you need to use this as well [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/LagCompensation]Player:LagCompensation[/url]
Thanks, the melee weapons work beautifully now. ^_^
Question though: Do guns act the same way? The same issue appears to happen when hitting a player with a bullet via a custom SWEP I made. Some shots deal damage when the target is running while other shots that appear to hit the target deal no damage at all.
I realize lag compensation would likely be a good solution to this, however, is it practical to use util.TraceHull / util.Traceline to guarantee self:FireBullets( BulletTable ) hits the target even though the BulletTable includes BulletTable.Dir and BulletTable.Src?
FireBullets already uses lag compensation, so unless you're using timers to fire your bullets, it should work fine already.
Sorry, you need to Log In to post a reply to this thread.