-- Get objects from orxonox thisscript:addObject("Claw", "spaceshipclaw") thisscript:addObject("RepairStation", "repair") thisscript:addObject("FPSPlayer", "Player") thisscript:addObject("SpaceShip", "spaceship") thisscript:addObject("GenericNPC", "mechanic") -- Global Variables playerEnteredSpaceShip = false playerReachedTrigger = false spaceshipOnPad = false spaceshipLaunchReady = false -- Returns the distance between (x1,x2,x3) and (y1,y2,y3) function dist( x1,x2,x3, y1,y2,y3 ) return math.sqrt( (x1-y1)^2 + (x2-y2)^2 + (x3-y3)^2 ) end function observePlayer() --playerEnteredSpaceShip = spaceship:hasPlayer() playerX = Player:getAbsCoorX() playerY = Player:getAbsCoorY() playerZ = Player:getAbsCoorZ() if dist( playerX,playerY,playerZ,678.946838, -11.959779, -920.512634 ) < 200 then playerReachedTrigger = true end end programRoute = true mheight = 5 function mechanicMove(timestep) if programRoute then mechanic:walkTo( 991.192261, mheight, -1878.394287) mechanic:walkTo( 976.976685, mheight, -1879.182129) mechanic:walkTo( 963.752625, mheight, -1880.202881) mechanic:walkTo( 948.094543, mheight, -1880.980713) mechanic:walkTo( 931.008606, mheight, -1880.974854) mechanic:walkTo( 917.888428, mheight, -1880.832764) mechanic:walkTo( 901.552368, mheight, -1880.655762) mechanic:walkTo( 886.475220, mheight, -1880.522949) mechanic:walkTo( 872.041504, mheight, -1880.545410) mechanic:walkTo( 851.380249, mheight, -1880.577637) mechanic:walkTo( 840.637512, mheight, -1880.594238) mechanic:walkTo( 828.564941, mheight, -1880.489868) mechanic:walkTo( 811.580322, mheight, -1880.085205) mechanic:walkTo( 801.953003, mheight, -1880.036377) mechanic:walkTo( 784.801086, mheight, -1880.280762) mechanic:walkTo( 774.514343, mheight, -1880.380005) mechanic:walkTo( 762.351746, mheight, -1880.248779) mechanic:walkTo( 750.737549, mheight, -1880.123413) mechanic:walkTo( 739.186890, mheight, -1879.999023) mechanic:walkTo( 728.210022, mheight, -1879.880371) mechanic:walkTo( 717.243835, mheight, -1879.761719) mechanic:walkTo( 708.253235, mheight, -1879.649048) mechanic:walkTo( 695.825867, mheight, -1877.611938) mechanic:walkTo( 687.077820, mheight, -1869.800659) mechanic:walkTo( 683.886963, mheight, -1859.888062) mechanic:walkTo( 685.589905, mheight, -1844.102051) mechanic:walkTo( 686.333069, mheight, -1837.212524) mechanic:walkTo( 687.256042, mheight, -1828.656860) mechanic:walkTo( 688.759583, mheight, -1820.024048) mechanic:walkTo( 690.621216, mheight, -1809.834595) mechanic:walkTo( 692.045593, mheight, -1803.566772) mechanic:walkTo( 695.021851, mheight, -1795.320923) mechanic:walkTo( 703.956360, mheight, -1789.028931) mechanic:walkTo( 711.400574, mheight, -1785.378418) mechanic:walkTo( 720.236267, mheight, -1782.750977) mechanic:walkTo( 741.346130, mheight, -1786.131836) mechanic:walkTo( 744.505798, mheight, -1788.214111) mechanic:walkTo( 753.788513, mheight, -1796.320557) mechanic:walkTo( 760.480408, mheight, -1804.107788) mechanic:walkTo( 765.918274, mheight, -1811.952393) mechanic:walkTo( 772.114990, mheight, -1823.565674) mechanic:walkTo( 776.130737, mheight, -1830.713989) mechanic:walkTo( 781.833313, mheight, -1836.770996) mechanic:walkTo( 796.051880, mheight, -1843.499512) mechanic:walkTo( 805.178101, mheight, -1844.844116) mechanic:walkTo( 816.733154, mheight, -1846.198608) mechanic:walkTo( 830.296326, mheight, -1844.374146) mechanic:walkTo( 841.234680, mheight, -1841.184814) mechanic:walkTo( 853.356201, mheight, -1837.650391) mechanic:walkTo( 866.242981, mheight, -1833.892944) mechanic:walkTo( 877.006836, mheight, -1830.820923) mechanic:walkTo( 889.236816, mheight, -1828.092773) mechanic:walkTo( 897.856689, mheight, -1826.204346) mechanic:walkTo( 909.685486, mheight, -1823.613037) mechanic:walkTo( 922.058777, mheight, -1819.907227) mechanic:walkTo( 933.861328, mheight, -1814.044800) mechanic:walkTo( 943.290588, mheight, -1809.960205) mechanic:walkTo( 952.188293, mheight, -1806.317261) mechanic:walkTo( 985.450745, mheight, -1800.297729) mechanic:walkTo( 1000.339722, mheight, -1800.916626) mechanic:walkTo( 1013.447937, mheight, -1802.642090) mechanic:walkTo( 1022.703430, mheight, -1808.694946) mechanic:walkTo( 1030.242554, mheight, -1821.859253) mechanic:walkTo( 1030.063354, mheight, -1839.935547) mechanic:walkTo( 1025.804932, mheight, -1864.135986) mechanic:walkTo( 1019.079651, mheight, -1878.196777) programRoute = false end if mechanic:finalGoalReached() then programRoute = true end end positionReached = false spaceShipReleased = false function moveToLaunchSite(timestep) if not positionReached then dx = 10 * timestep dy = 0 * timestep dz = 0* timestep end if not spaceShipReleased and positionReached then dx = 0 * timestep dy = 10 * timestep dz = 0 * timestep end if positionReached and spaceShipReleased then dx = 0 * timestep dy = 1 * timestep dz = 0 * timestep end if spaceshipOnPad then if not spaceShipReleased then --spaceshipclaw:playAnimation(1,1) io.write("release spaceship\n") spaceShipReleased = true playerEnteredSpaceShip = true end --if clawY > 100 then spaceshipLaunchReady = true --end end -- set new coordinates --clawX = claw:getAbsCoorX() --clawY = claw:getAbsCoorY() --clawZ = claw:getAbsCoorZ() --claw:setAbsCoor(clawX + dx, clawY + dy, clawZ + dz) spaceshipX = spaceship:getAbsCoorX() spaceshipY = spaceship:getAbsCoorY() spaceshipZ = spaceship:getAbsCoorZ() spaceship:setAbsCoor(spaceshipX + dx, spaceshipY + dy, spaceshipZ + dz) --if dist( clawX,clawY,clawZ,1020.025024, -11.959781, -1721.614380 ) < 60 then if dist( spaceshipX,spaceshipY,spaceshipZ,1020.025024, -11.959781, -1721.614380 ) < 60 then positionReached = true end --if dist( clawX,clawY,clawZ,167.361526,29,483.163818 ) < 60 then if spaceshipY > 10 then spaceshipOnPad = true end end hoverPosReached = false function launchSpaceShip(timestep) if not hoverPosReached then dx = 0 * timestep dy = 1 * timestep dz = 0 * timestep else dx = 200 * timestep dy = 0 * timestep dz = 0 * timestep end spaceshipX = spaceship:getAbsCoorX() spaceshipY = spaceship:getAbsCoorY() spaceshipZ = spaceship:getAbsCoorZ() spaceship:setAbsCoor(spaceshipX + dx, spaceshipY + dy, spaceshipZ + dz) if spaceshipY > 15 then hoverPosReached = true end end function tick(timestep) observePlayer() mechanicMove(timestep) if playerReachedTrigger and not spaceshipLaunchReady then moveToLaunchSite(timestep) end if spaceshipLaunchReady then launchSpaceShip(timestep) end return false end