Share Your Code

Flight Path

Posted by carlos m. icaza, Posted on June 2, 2011, Last updated October 18, 2011

GitHub URL: 
https://github.com/ansca/Flight-Path

You are in charge. You are the Head Honcho at the new Nimitz class of nuclear powered aircraft carrier and your job is to make sure that every plane/helicopter lands safely.

This sample project is provided for you learn a different type of game that can be developed using Corona. It is up to you now to implement sound, different planes, water movement, score, etc.

The code is very simple to follow and as usual it is open source MIT license so feel free to use it for your own projects, or just to impress your friends.

One thing, this game sample has coordinate systems for iPad - looks funky on some other devices.

ps: there are some quirks but really minor. ...
pss: Catmull Spline code thanks to Matthew Pringle for submitting it to our code exchange.


Replies

Mike_Lorenz
User offline. Last seen 11 weeks 1 day ago. Offline
Joined: 1 Oct 2010

Brilliant! Whippin' out the Catmull splines!

autolib
User offline. Last seen 27 weeks 11 hours ago. Offline
Joined: 19 Jan 2011

After installation on an iPhone or iPad all I get is a black screen. Any idea what is wrong?

izzthetruth
User offline. Last seen 2 years 38 weeks ago. Offline
Joined: 31 Oct 2010

yepp same issue here, doesnt show when i tried it out on my iPod Touch 4th generation, whats going on?

carlos m. icaza
User offline. Last seen 2 years 15 weeks ago. Offline
Alumni
Joined: 22 Jun 2009

You guys have the source? can't you debug?

What build number are you using? this works with the latest build.

C.

jakescarano
User offline. Last seen 1 year 3 weeks ago. Offline
Joined: 8 Apr 2011

Hey Carlos, is there any way for me to see an example with just one plane connect with the ship. The plan being placed in one place not moving.

Basically I want to see how this code works with just one still object (plane) connect with another still object (ship).

I am very new and get confused with all the randomness going on..

jakescarano
User offline. Last seen 1 year 3 weeks ago. Offline
Joined: 8 Apr 2011

Well I managed to rip apart the Flight control project to where it just shows one plane and the run way.
I was wondering if there was a way to set up boundaries where the plan can't fly outside of those boundaries. Say we had a maze that the plane had to fly through. If the plane tried to go through a wall it would cancel its path. is this possible?

WauloK
User offline. Last seen 1 year 41 weeks ago. Offline
Joined: 21 Oct 2010

It's good but it has the same issue I saw in Martian Control in that under some circumstances when a vehicle crashes, the line is not erased and remains for the rest of the game.

Jorge Sanchez
User offline. Last seen 12 hours 16 min ago. Offline
Joined: 1 Aug 2011

I downloaded this last night to have a look, and I noticed that sometimes planes "lose" their path and go off screen. I think it happens when the paths of different planes intersect or when the paths end at the landing area close together. I started to look at the code to see where this gremlin was hiding but I can't figure it out. Any thoughts? Also, I'm VERY new to lua so it might be something obvious I'm missing. Thanks

tyrese_eric
User offline. Last seen 21 weeks 5 days ago. Offline
Joined: 30 Jul 2011

Hi all,

I installed the latest build and built this sample code, but i still encountered the same issue -- there was a black screen in my iPhone3.

Could anyone please give me some suggestions about how to resolve this ?

Thank you in advance.
Eric.W

AParachutingFrog
User offline. Last seen 1 year 14 weeks ago. Offline
Joined: 13 Nov 2011

Really great example of catmull splines but for a novice like me in game development I struggled to get my head round this at first.

As a result I have applied this code to a simpler example providing as many comments and references back to the SDK as well as the concept of catmull splines.

I hope my research into this subject helps. I have two postings at http://mygamingproject.blogspot.com/2011/12/catmull-splines-introduction.html and http://mygamingproject.blogspot.com/2011/12/catmull-splines-object-follows-path.html

The intention is to continue my study of which I will report further postings. Once finished will submit to the code exchange

Falcon777
User offline. Last seen 3 hours 4 min ago. Offline
Joined: 17 Jun 2011

Sometimes, the plane will lose track of the path. I am yet to find what is causing this problem. Anyone has any idea?

fatcow240
User offline. Last seen 29 weeks 5 days ago. Offline
Joined: 2 Apr 2012

I have found that this is due to a velocity too close to zero.

Solution 1
To correct this I added code to the followPoints(plane) method to ensure a high enough velocity.

Original Code:

1
2
3
4
local flightAngle = math.atan2((plane.y - point.y) , (plane.x - point.x) ) * (180 / math.pi)
        
        local velocityX = math.cos(math.rad(flightAngle)) * planeSpeed * -1
        local velocityY = math.sin(math.rad(flightAngle)) * planeSpeed * -1

Modified Code:

1
2
3
4
5
6
7
8
9
10
        local flightAngle = math.atan2((plane.y - point.y) , (plane.x - point.x) ) * (180 / math.pi)
        
        local velocityX = math.cos(math.rad(flightAngle)) * planeSpeed * -1
        local velocityY = math.sin(math.rad(flightAngle)) * planeSpeed * -1
        while(math.abs(velocityX) < 0.001)do
                velocityX = velocityX * 10
        end
        while(math.abs(velocityY) < 0.001)do
                velocityY = velocityY * 10
        end

Solution 2
To correct this I modified code in the checkForNextPoint method. The new code only checks if the plane is close enough to the point, not if it has passed it.

Original Code:

1
2
if(     (velX < 0 and plane.x < dest.x and velY < 0 and plane.y < dest.y) or  (velX > 0 and plane.x > dest.x and velY < 0 and plane.y < dest.y) or
                                (velX > 0 and plane.x > dest.x and velY > 0 and plane.y > dest.y) or  (velX < 0 and plane.x < dest.x and velY > 0 and plane.y > dest.y) or #plane.points == 0) then

Modified Code:

1
if( (math.abs(dest.x - plane.x) < 1) and (math.abs(dest.y - plane.y) < 1) or #plane.points == 0) then

friskypigstudios
User offline. Last seen 14 weeks 5 days ago. Offline
Joined: 2 Nov 2011

I'm also trying to run the Flight Path demo on my Android device and getting the "This application has been corrupted" error. Have build multiple apps with Corona so far for iOS and Android. This is the first, that doesn't work.