burgelkat Posted October 18, 2016 Share Posted October 18, 2016 Hallo, i need help with a script. Base is the platform lua. I use it with a helicopter. The Helicopter should flight the path and always change the rotation to the next target. the flight path function. (not yet smooth but this later on , at this time i dont know how to start, so that have to wait) Now the helicopter flight the pass, look at the next target... but the helicopter turns themself 180 degrees. so it looks he flight back what i do wrong? i hope someone can help me this is the code Script.enabled = true --bool "Enabled" Script.speed = 10 --float "Speed" Script.target = "" --entity "Target waypoint" Script.originPosition = nil Script.targetPosition = nil Script.currentPosition = nil Script.currentRotation = nil Script.moving = nil Script.oldMass = nil Script.pointtarget = nil--entity "Point target at" function Script:Start() self.oldMass = self.entity:GetMass() if self.enabled then if self.entity:GetMass()==0 then Debug:Error("Entity mass must be greater than zero.") end else self.entity:SetMass(0) end self.entity:SetGravityMode(false) self.entity:SetCollisionType(Collision.Scene) if self.target == nil then Debug:Error("No target assigned") end self:SetTarget(self.target) end function Script:SetTarget(newTarget) self.currentPosition = self.entity:GetPosition() self.originPosition = self.entity:GetPosition() self.targetPosition = newTarget:GetPosition() if self.pointtarget ~= nil then self.entity:Point(self.pointtarget) else self.target:GetRotation(nextStepRot.x, nextStepRot.y, nextStepRot.z, true) end self.distance = self.originPosition:DistanceToPoint(self.targetPosition) self.target = newTarget local pos = self.entity:GetPosition(true) local targetpos = self.target:GetPosition(true) local pin = pos - targetpos self.distance = pin:Length() pin = pin:Normalize() if self.joint then self.joint:DisableMotor() self.joint:Release() end self.joint=Joint:Slider(targetpos.x,targetpos.y,targetpos.z,pin.x,pin.y,pin.z,self.entity,nil) self.joint:EnableMotor() self.joint:SetMotorSpeed(self.speed) self.joint:SetAngle(-self.distance) end function Script:UpdatePhysics() if self.enabled then --Calculate movement local currentpos = self.entity:GetPosition(true) local targetpos = self.target:GetPosition(true) local d = currentpos:DistanceToPoint(targetpos) if d<0.1 then --When the target has been reached --self.entity:PhysicsSetPosition(self.targetPosition.x, self.targetPosition.y, self.targetPosition.z) --self.enabled = false self.component:CallOutputs("WaypointReached") --Check if the target that we have reached also has a target, which is then our new target/waypoint if self.target.script.target ~= nil then self:SetTarget(self.target.script.target) end end end end ----------------------------------------------------------------------------------- function Script:Enable()--in self.enabled = true self.entity:SetMass(self.oldMass) -- this line was missing [einlander] self.entity:AddForce(0,0.001,0) -- give it a tiny push to get it moving [einlander] end function Script:Disable()--in self.enabled = false self.entity:SetMass(0) end Quote Link to comment Share on other sites More sharing options...
burgelkat Posted October 18, 2016 Author Share Posted October 18, 2016 it looks that i have to change the model direction .... it is wrong Quote 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.