• bad argument #2 to '?' (Vector expected, got number)
    8 replies, posted
Hey, I want to trace perpendicularly to a trace hitpos but am running into a weird problem. Can anyone tell me what I'm doing wrong, or what I should be doing? Here's what I have : [lua]local tr = self:GetEyeTrace() local endpos = tr.HitPos + tr.HitNormal*100 print(type(tr.HitPos), type(endpos)) -- Prints Vector Vector local hittr = util.QuickTrace(tr.HitPos, endpos) -- bad argument #2 to '?' (Vector expected, got number) [/lua] Thanks in advance. :smile:
It should work fine actually. (It does for me at least) Have you tried using util.TraceLine instead? (util.TraceLine({start = tr.HitPos, endpos = tr.HitPos +endpos}))
Shouldn't do any difference, but try: [lua]local tr = Vector(self:GetEyeTrace()) local endpos = Vector(tr.HitPos + tr.HitNormal*100) print(type(tr.HitPos), type(endpos)) -- Prints Vector Vector local hittr = util.QuickTrace(tr.HitPos, endpos) -- bad argument #2 to '?' (Vector expected, got number) [/lua]
[QUOTE=| FlapJack |;18113365]Shouldn't do any difference, but try: [lua]local tr = Vector(self:GetEyeTrace()) local endpos = Vector(tr.HitPos + tr.HitNormal*100) print(type(tr.HitPos), type(endpos)) -- Prints Vector Vector local hittr = util.QuickTrace(tr.HitPos, endpos) -- bad argument #2 to '?' (Vector expected, got number) [/lua][/QUOTE] What are you doing? That will set tr to Vector(1,1,1), I don't see how that's supposed to help...
Sorry guys, I'm an idiot. That's not even what was giving me an error.:blush: (I had assumed) Problem fixed.
[QUOTE=Silverlan;18113446]What are you doing? That will set tr to Vector(1,1,1), I don't see how that's supposed to help...[/QUOTE] So tonumber will turn 5 into 1? [/sarcasm] And if it doesn't return the way it should, just use .x .y and .z. Problem solved.
[QUOTE=| FlapJack |;18113485]So tonumber will turn 5 into 1? [/sarcasm] [/QUOTE] No, but you can't use a table as an argument for Vector(). If you don't use numbers, or anything at all, Vector() always returns a vector with x = 1, y = 1 and z = 1. [EDITLINE]-[/EDITLINE] By the way, quebec, small mistake in your code. The second argument of util.QuickTrace is not supposed to be a world position. It automatically adds the vector given through the first argument to the second argument, so in this case it would create a trace from tr.HitPos to tr.HitPos +tr.HitNormal *100 +tr.HitPos, and I'm pretty sure that's not what you want. Just change it to this: [lua]local tr = self:GetEyeTrace() -- local endpos = tr.HitPos + tr.HitNormal*100 local enddir = tr.HitNormal*100 local hittr = util.QuickTrace(tr.HitPos, enddir) [/lua]
[QUOTE=Silverlan;18113536]No, but you can't use a table as an argument for Vector(). If you don't use numbers, or anything at all, Vector() always returns a vector with x = 1, y = 1 and z = 1. [EDITLINE]-[/EDITLINE] By the way, quebec, small mistake in your code. The second argument of util.QuickTrace is not supposed to be a world position. It automatically adds the vector given through the first argument to the second argument, so in this case it would create a trace from tr.HitPos to tr.HitPos +tr.HitNormal *100 +tr.HitPos, and I'm pretty sure that's not what you want. Just change it to this: [lua]local tr = self:GetEyeTrace() -- local endpos = tr.HitPos + tr.HitNormal*100 local enddir = tr.HitNormal*100 local hittr = util.QuickTrace(tr.HitPos, enddir) [/lua][/QUOTE] Oh, quite right you are, I had misread the documentation. Thanks. :smile:
What were you reading?
Sorry, you need to Log In to post a reply to this thread.