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

Maybe some of you did not notice it, but there was a real pearl in a comment of Create a flash draw game blike Line Rider or others – A different approach – Part 2 post.

Jesuson studied all the source codes and came up with this comment:


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;

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
px=w._x w.radius*Math.sin(i*360/precision);
px=w._x w.radius*Math.sin(i*Math.PI/precision);

The second is, what happend if there are diferent points of collisions? for expample if ball collide with floor and wall, you don’t must take it like a single collision, becouse the response won’t be good.
For fix it I take all the collisions points what are together (For detect than it´s together you have to detect them in order like I said)and put it in a collision group array, and then I calculate diferents responses with diferent arrays.

Here you can see what I’m speaking about:
Bad method –>
Good method –>

Look what happend in two cases when the ball hit the wall.
note: use up/down to acelerate/brake.


I downloaded both methods and the “good” one is… really good!

This is the actionscript with some comments from the author

And this is the result (up and down arrows to move the ball)

Now I am going to study more in depth this work because I find it really interesting, so expect a tutorial based on this code during next days.

And this is the source code hosted on my site, just in case some day the link provied by Jesuson should disappear.

  • Pingback: Create a flash draw game like Line Rider or others - A different approach at Emanuele Feronato()

  • Pingback: Create a flash draw game like Line Rider or others - A different approach - Part 2 at Emanuele Feronato()

  • mousey

    Nice, also will there be a tutorail coming up showing us how to go in the toher direction because at the moment the ball or objest only move one way and constantly accelerates!

    Very good Though.

  • Callum

    Wow, thats brillian. My game is nearlly finished. YOu are truley the greatest Emanuele in the world [:

  • Jesuson

    I’m happy to see you liked this. I want to tell you about another problem with my code.
    When I work with the array of points, this array represent the collision points of the circle, and calculate the collisions zones(points together),but, if there are points in the beginning and in the end of the array, THIS IS THE SAME ZONE.
    You will see this problem if you change the gravity to a negative value, then, when the ball collision with the roof the response is not good.

    I will post my solution (is a good one for my game, but is not the best) with better comments, sorry for this in last one, I didn’t know you would post it here.

    See you!!

  • Jesuson

    Forgot to show you this first example. This is a game a made when I started to study your tutorials.The collisions are based in distance between a line and a point, and not using hitTest.
    The game hadn’t got good scores on newground :(, so I would like to share with all of you the code.

    Notice than this one has got a worst script level, so don’t take it like a good way doing things.

  • how would you make it so when you get tho a point like end so it goes to the next level?????

  • splashy5, You would have to make a hitTest and when the the ball hit the dot, it would take you to the frame with the next level.

  • alex

    how do you make the ball rotate when it moves

  • alex

    nevermind i got it

  • Dudeson

    Hi, I know it’s been a few years but is there going to be a part four of this? I am having troubles combining the camera movement into the one where you can draw, is there any one that can help?