Is there a better way to do this:
[lua] local ply = self.Owner;
local tr = util.QuickTrace( ply:GetShootPos(), ply:GetAimVector() * 5, { ply } );
[/lua]
I've tried debugging:
[lua] if tr.HitWorld then
print("hit world");
else
print("didnt hit world");
end
if !tr.Hit then
print("stopped in air");
else
print("hit something");
end
[/lua]
But it keeps printing "didnt hit world" or "stopped in air".
By the way, I'm calling the trace in SWEP:PrimaryAttack().
That would check if it's 5 units in front of the shoot pos, which I'm not even sure is out of the player's bounding box. I'm doing this for my crowbar remake:
[lua]
function SWEP:CanPrimaryAttack()
local TraceRes = self.Owner:GetEyeTrace()
if(TraceRes.StartPos:Distance(TraceRes.HitPos) > 75) then return false end
return true
end
[/lua]
[QUOTE=PortalGod;29678848]That would check if it's 5 units in front of the shoot pos, which I'm not even sure is out of the player's bounding box.[/QUOTE]
Thank you for that, I got it working!
ply.tracehullattack() is better for melee weapons
[url]http://wiki.garrysmod.com/?title=Player.TraceHullAttack[/url]
What are you lot doing!
He should be using dmginfo not traces.
[QUOTE=Science;29754742]What are you lot doing!
He should be using dmginfo not traces.[/QUOTE]
I'm using Entity.TakeDamageInfo.
[QUOTE=PortalGod;29678848]That would check if it's 5 units in front of the shoot pos, which I'm not even sure is out of the player's bounding box. I'm doing this for my crowbar remake:
[lua]
function SWEP:CanPrimaryAttack()
local TraceRes = self.Owner:GetEyeTrace()
if(TraceRes.StartPos:Distance(TraceRes.HitPos) > 75) then return false end
return true
end
[/lua][/QUOTE]
Why don't you just do:
[lua]
function SWEP:CanPrimaryAttack()
local tr = util.TraceLine({start = self.Owner:EyePos(), endpos = self.Owner:EyePos() + self.Owner:GetAimVector() * 75, filter = self.Owner})
return tr.Entity ~= NULL
end
[/lua]
[QUOTE=Loures;29755408]Why don't you just do:
[lua]
function SWEP:CanPrimaryAttack()
local tr = util.TraceLine({start = self.Owner:EyePos(), endpos = self.Owner:EyePos() + self.Owner:GetAimVector() * 75, filter = self.Owner})
return tr.Entity ~= NULL
end
[/lua][/QUOTE]
[QUOTE=Science;29754742]What are you lot doing!
He should be using dmginfo not traces.[/QUOTE]
Thats why.
Then how are you going to check the player's distance?
[QUOTE=Loures;29757749]Then how are you going to check the player's distance?[/QUOTE]
Quick trace find the player then use DMG_SLASH as the damage type.
Sorry, you need to Log In to post a reply to this thread.