# Create a flash draw game like Line Rider or others – A different approach – Part 2

June 15th update: part 3 released

I am glad to publish a very interesting upgrade to Create a flash draw game like Line Rider or others – A different approach by Kevin Ward.

Kevin strikes back with three very interesting prototypes I am currently studying in order to optimize his ideas.

I suggest you all to read carefully his article.

——

The physics in the file has quite a flaw in that it seems to bounce the right direction but it loses speed.
If you change it to use the variation I sent you after that, it has all the speed, but it goes in the wrong direction.

This is quite a quandary to me with my lack of experience, so I’ve been working on it exhaustively for the past few days.
The physics has not quite improved yet, but I did create a platform for testing the physics that allows you to draw, erase, and reset the terrain, and I came up with some interesting outcomes.

Natually I did some research after my attempt proved itself imperfect and I found an excellent document covering 2D collisions of two objects with vectors, available here http://www.geocities.com/vobarian/2dcollisions/.

It outlines the seven steps to finding the final velocities of the two objects. You find the vector between the two objects, called the normal, then give it a magnitude of one.
The next step is to find a vector perpendicular to the normal vector.
This I knew nothing about before.
It’s called the tangent, and basically you add the normal velocity and the tangent velocity vectors together.

This works beautifully for two round objects with masses, but it implies that one object will lose velocity and another will gain.
Unfortunately, things get complicated when you’re trying to keep the velocity all in one object and bounce it off the terrain.
I think the answer lies in working the equations pretending that the terrain is the one moving and it has a mass equal to that of the ball.
I understand that in a collision between a stationary object and a moving object of the same mass, velocity will be traded.
I haven’t tried this yet because I think I’ve worked on one project enough for one night.

I’m going to include three files for your perusal.

The first is a successful simulation of 2D collisions between round objects.

The second and third are attempts at ball and terrain interaction with drawable terrain.
You’ll notice that both have a tendency toward one direction of bounce, which is the problem.
The problem of course if bad math, and I’m abandoning that approach for one I believe might actually work.
However, the third is interesting because velocity is transferred along the tangential vector and it seems to slide.
I’m interesting to know if that’s similar to how you plan to show us.

One more thing: I’m in the process of turning the first file’s functions into classes so I can more easily handle more than two objects.
Almost more than anything else, I would like to know how you think I could perform a collision check and collision reaction amongst many objects.

Thanks again, and by the way, I am from north-eastern Texas, USA, I’m seventeen-years old, a high school student, and I’ve been working in Flash and interested in other programming since January.
I’m also a guitarist and I draw a little here and there.

——

The “collision check and collision reaction amongst many objects” is a thing I am practicing right now, so expect a tutorial within some days.

Meanwhile, I am going to publish Kevin’s attempts

Momentum

Line rider drawing

Line rider sliding

And there are the source codes.

I think Kevin is very close to the solution, let’s us help him with feedback.

• abhilash

cool and nice

• This is great!

CAN YOU PLEASE MAKE A TUTORIAL ON HOW TO MAKE A SIMPLE DEFENCE GAME?

• mousey

Much better congrats!

• Peh

COOL!
Keep up with your good work!!!

• abhilash

i understood thing but i could not understand how to make buttons and rider

• zak

wow this is great stuff!!!!

• Callum

How do I remove the green lines :S

i do not understand, the flash actionscript does not work on my computer

• Jesuson

I have been testing it and it chash a lot of times. I would change next things:
1. For the collision response, to calculate the out velocity I would use

vx1=-cosa*w.vx sina*w.vy;
vy1=(-cosa*w.vy-sina*w.vx)*bounce;

w.vx = -cosa*vx1-sina*vy1; //ball X velocity
w.vy = -cosa*vy1 sina*vx1; //ball Y velocity

Now it has got aceleration and velocity won’t be infinite.

2. There is some problems when you test the perimeter of the ball for collisions. The first is you don’t do it in order. For do it in order change
by