-- Get objects from orxonox thisscript:addObject("Claw", "spaceshipclaw") thisscript:addObject("RepairStation", "repair") thisscript:addObject("FPSPlayer", "Player") thisscript:addObject("SpaceShip", "spaceship") thisscript:addObject("SpaceShip", "spaceship2") -- 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,167.361526,29,483.163818 ) < 60 then playerReachedTrigger = true end end positionReached = false spaceShipReleased = false function moveToLaunchSite(timestep) if not positionReached then dx = 1 * timestep dy = 0 * timestep dz = 1* timestep end if not spaceShipReleased and positionReached then dx = 0 * timestep dy = -1 * 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) spaceShipReleased = 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) if dist( clawX,clawY,clawZ,167.361526,29,483.163818 ) < 60 then positionReached = true end if dist( clawX,clawY,clawZ,167.361526,29,483.163818 ) < 60 then spaceshipOnPad = true end end --observePlayer hoverPosReached = false function launchSpaceShip(timestep) if not hoverPosReached then dx = 0 * timestep dy = 1 * timestep dz = 0 * timestep else dx = 1 * timestep dy = 0 * timestep dz = 1 * timestep end spaceshipX = spaceship:getAbsCoorX() spaceshipY = spaceship:getAbsCoorY() spaceshipZ = spaceship:getAbsCoorZ() spaceship:setAbsCoor(spaceshipX + dx, spaceshipY + dy, spaceshipZ + dz) if spaceshipY > 50 then hoverPosReached = true end end function tick(timestep) --io.write("Spaceship called \n") observePlayer() if playerReachedTrigger then --moveToLaunchSite(timestep) end if spaceshipLaunchReady then --launchSpaceShip(timestep) end return false end