Hi, I am having trouble with the thrusters for a rocket. Once the rocket has been destroyed, occasionally an error appears that says “Attempt to perform arithmetic on field ‘rotation’ (a nil value)”. I believe it may have something to do with the rocket being nil when the necessary calculations are performed. Here is the collision code and the thruster calculation code:
rocketCollision = function(self, event) local other = event.other other.health = other.health - self.damage self.health = self.health - other.damage if event and event.phase == "began" then if self.health \< 0 then explosion.new(self.parent, self.x, self.y, 0.5, 0.5, math.random(-20, 20), math.random(-20, 20)) ignore("enterFrame", self) display.remove(self.thruster) display.remove(self) end end end moveThruster = function(self) local thruster = self.thruster local vec1 = angle2Vector( self.rotation + 180, true) \<--error line vec1 = vecNorm( vec1 ) vec1 = vecScale( vec1, thruster.yOffset ) vec1 = vecAdd( vec1, self ) local vec2 = angle2Vector( self.rotation + 90, true ) vec2 = vecNorm( vec2 ) vec2 = vecScale( vec2, thruster.xOffset ) thruster.rotation = self.rotation thruster.x = vec1.x + vec2.x thruster.y = vec1.y + vec2.y end
Any help would be great, thank you!