What would it take to make a dispatched attack do damage to anything the world model touches? Should I be tracing a line from the hand to the end of the weapon each frame (or every other frame)?
Are there any clever optimized ways of doing this?
This is what I've done as a test.
[vid]http://puu.sh/aHdaj/f124e605e5.webm[/vid]
[url]http://puu.sh/aHdaj/f124e605e5.webm[/url]
[lua]
AddCSLuaFile()
if SERVER then
util.AddNetworkString( "debugswing" )
end
if CLIENT then
local lines = {}
hook.Add( "HUDPaint", "debuswing", function()
surface.SetDrawColor( 255, 255, 255, 64 )
for k, v in pairs( lines ) do
if CurTime() >= v.c then
lines[k] = nil
continue
end
local a = v.a:ToScreen()
if !a.visible then continue end
local b = v.b:ToScreen()
if !b.visible then continue end
surface.DrawLine( a.x, a.y, b.x, b.y )
end
end )
net.Receive( "debugswing", function()
local a = net.ReadVector()
local b = net.ReadVector()
table.insert( lines, { a = a, b = b, c = CurTime() + 1 } )
end )
end
SWEP.PrintName = "Melee"
SWEP.Author = "Dane"
SWEP.Spawnable = true
SWEP.DrawAmmo = false
SWEP.UseHands = true
SWEP.ViewModel = "models/weapons/c_crowbar.mdl"
SWEP.WorldModel = "models/weapons/w_crowbar.mdl"
SWEP.ViewModelFOV = 52
SWEP.Slot = 0
SWEP.SlotPos = 1
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
local SwingSound = Sound( "weapons/slam/throw.wav" )
function SWEP:Initialize()
self:SetHoldType( "melee2" )
end
function SWEP:Think()
if SERVER then
local a = self:GetNextPrimaryFire() - CurTime()
if a < 0.75 and a > 0.55 then
local owner = self.Owner
local attach = owner:GetAttachment( owner:LookupAttachment( "anim_attachment_rh" ) )
net.Start( "debugswing" )
net.WriteVector( attach.Pos )
net.WriteVector( attach.Pos + ( attach.Ang:Up() * 32 ) )
net.Send( owner )
end
end
end
function SWEP:PrimaryAttack()
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self.Weapon:SendWeaponAnim( ACT_VM_SWINGMISS )
self:EmitSound( SwingSound, 100, 100 + math.random(50) )
self:SetNextPrimaryFire( CurTime() + 1 )
end[/lua]
You should do it perpendicular to what it is currently. That way it'll catch things in the path instead of having dead zones.
[img]http://puu.sh/aHkjY/087b37f904.png[/img]
From one point to the next in sequence.
[img]http://puu.sh/aHrVU/3d92ef34e0.png[/img]
Sorry, you need to Log In to post a reply to this thread.