straightdrive = {}; function straightdrive.prerequisitesPresent(specializations) return true; end function straightdrive:load() end function straightdrive:draw() if self.aiLeftMarker ~= nil and self.aiRightMarker ~= nil and self.aiBackMarker ~= nil then if self.KompassX and self.KompassZ then g_currentMission:addHelpButtonText(g_i18n:getText("Drive on"), InputBinding.Driveon); if InputBinding.hasEvent(InputBinding.Driveon) then if self.fahren then self.fahren = false else self.aiTractorDirectionX = self.KompassX;self.aiTractorDirectionZ = self.KompassZ;self.fahren = true end end if self.fahren then local x,y,z = getWorldTranslation(self.rootNode); local dirX, dirZ = self.aiTractorDirectionX, self.aiTractorDirectionZ; local targetX, targetZ = self.aiTractorTargetX, self.aiTractorTargetZ; local dx, dz = x-targetX, z-targetZ; local dot = dx*dirX + dz*dirZ; local projTargetX = targetX +dirX; local projTargetZ = targetZ +dirZ; newTargetX = projTargetX+self.aiTractorDirectionX*dot; newTargetY = y; newTargetZ = projTargetZ+self.aiTractorDirectionZ*dot; local lx, lz = AIVehicleUtil.getDriveDirection(self.rootNode, newTargetX, newTargetY, newTargetZ); AIVehicleUtil.driveInDirection(self, dt, 25, 0.5, 0.5, 20, true, true, lx, lz, 1, 0.9); end end local x,y,z = localDirectionToWorld(self.rootNode, 0, 0, 1); local length = Utils.vector2Length(x,z); local dX = x/length local dZ = z/length local x,y,z = getWorldTranslation(self.rootNode); self.aiTractorTargetX = x; self.aiTractorTargetZ = z; local TEntfernung = math.sqrt(dX * dX + dZ * dZ) local TRichtung = math.deg(math.atan2(dX,dZ)) if TRichtung < 0 then TRichtung = 360 - (TRichtung * -1) end renderText(0.85,0.77,0.03,string.format("Richtung: %f ",360 - math.floor(TRichtung + 0.5) )); self.KompassX = TEntfernung * math.sin(math.rad( math.floor(TRichtung + 0.5)) ) self.KompassZ = TEntfernung * math.cos(math.rad( math.floor(TRichtung + 0.5)) ) end end function straightdrive:update() end function straightdrive:delete() end; function straightdrive:mouseEvent(posX, posY, isDown, isUp, button) end function straightdrive:keyEvent(unicode, sym, modifier, isDown) end;