Attempt to perform arithmetic on a userdata value error
4 replies, posted
[code] local rocketangles = self:GetAngles()
local newrocketangles = relativevector:Angle()
self:SetAngles((rocketangles+newrocketangles)/2) <-- Line 22
[/code]
This code gives me error spam:
entities/gstruction_hrocket/init.lua:22: attempt to perform arithmetic on a userdata value
I have no idea what the error is telling me and I have no idea why I can't touch my angles :(
You can't perform a division on an Angle object.
[code]local ang = rocketangles+newrocketangles
local newang = Angle(ang.p/2, ang.y/2, ang.r/2)
[/code]
[editline]11:33AM[/editline]
You could also edit the Angle metatable to allow for division.
Something like this:
[code]function _R.Angle.__div(a)
if type(a) == "number" then
return Angle(self.p/a, self.y/a, self.r/a)
end
end[/code]
Well it's no longer giving me errors, but my idea was broken from the start.
Do you have any idea for how I could limit how much the rockets angle changes every frame?
Rather than having a rocket that can turn on a dime I'd prefer one that turns slowly.
Any ideas?
[url=http://wiki.garrysmod.com/?title=PhysObj.ComputeShadowControl]ComputeShadowControl[/url] could be just the thing you are looking for, although it may also be nothing to do with it.
Yeah this is confusing as hell.
And now my entity doesn't explode, it bounces off walls. Perhaps not.
[editline]09:37PM[/editline]
I looked at the drunken_rocket script by tetabonita and looked how he did it.
It seems to be working now. And after I got the basic slowed angle change down I developed my own wobble, since I don't like to copypaste code.
Sorry, you need to Log In to post a reply to this thread.