NoIE Posted December 12, 2014 Share Posted December 12, 2014 code:Script.parentObj = nil--entity function Script:Start() self.center = self.entity:FindChild("center") if self.center~= nil then local pos = self.center:GetPosition(true) self.jointBall = Joint:Ball(pos.x, pos.y,pos.z,self.entity,self.parentObj) ------------------------------------------------------------------------------------------------------ -- There are also "self.parentObj:Get...", but it will not cause problems. self.length = pos:DistanceToPoint(self.parentObj:GetPosition(true)) ------------------------------------------------------------------------------------------------------ end end --[[function Script:Collision(entity, position, normal, speed) --if speed> 0.01 and entity.script.tag ~= nil and entity.script.tag == "player" then -- entity.script:TakeDamage(3) --end end]]-- function Script:UpdatePhysics() local pp = self.parentObj:GetPosition(true) local cp = self.center:GetPosition(true) local d = cp local length = d:Length() --if length > self.length+0.1 then -- local np = pp + d:Normalize()*self.length - (cp - self.entity:GetPosition(true)) -- self.entity:SetPosition( (self.entity:GetPosition(true)*3 + np )/4 , true) --end end When I commented " local pp = self.parentObj:GetPosition(true)", it can run, otherwise break immediate. It without any warning. 1 Quote Please forgive my poor English. Link to comment Share on other sites More sharing options...
Rick Posted December 12, 2014 Share Posted December 12, 2014 What did you link to parentObj in the editor? If it's csg then it needs a mass or script attached otherwise it won't be treated as a valid entity as it gets collapsed into nothingness (I don't know, I hear it gets collapsed and not sure what that means but I know it means it's not treated as an entity). Quote Link to comment Share on other sites More sharing options...
NoIE Posted December 12, 2014 Author Share Posted December 12, 2014 What did you link to parentObj in the editor? If it's csg then it needs a mass or script attached otherwise it won't be treated as a valid entity as it gets collapsed into nothingness (I don't know, I hear it gets collapsed and not sure what that means but I know it means it's not treated as an entity). My program will start running and then close immediately. I think I linked parentObj, Because Start function uses parentObj. I also checked the editor. Just now, I tried to remove the link, and then I find Script Error attempt to index field 'parentObj' (a nil value) Line 12 Quote Please forgive my poor English. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.