Constant speed through B�zier curve?

0 favourites
  • 5 posts
From the Asset Store
Have you ever dreamed of playing in a Speedball game or tournament?
  • I've been working on a vertical shooter and right now I'm tackling enemy A.I. using self constructed paths. I've got things working so that each enemy sets its next WP, the speed it should use to get there and if it should pause when reaching it.

    The thing is that all the movements are strictly linear and as you may know, this is hardly the case for enemy movement in vertical shooters. So i was playing around trying to implement B�zier curves which i had some real problems with. Eventually i got it to work using to points in space and one control handle, a Quadratic B�zier curve.

    The problem i have though is that the formula i got working isn't taking into account the enemy speed, but only moves along the curve by setting X/Y positions each tick. Secondly, this isn't time based animation taking into account the delta-time which will make the animation slower on slow machines. How can i implement a constant time based animation across a B�zier curve?

    This is the code I' am using:

    <img src="http://i.imgur.com/wpOrzY7.png" border="0" />

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • This looks like code that would work perfectly with the lerp (linear interpolation) exppression.

    When I'm on my home-pc I'll brainstorm a bit within Construct.

    I'll be back!

  • I'm still trying to find a solution to this and math is not my strong side. As i understand it, getting a constant speed through a Bezier curve is impossible but you could get pretty close by calculating the arc length?

    The problem is that you can't have a Shoot em up without having some advanced patterns for the enemies and the only thing i can think of is using bezier curves. If anyone has any other suggestions that would be great ^^

  • A way to do it would be to convert the bezier curve to a polyline. The more points you use the better the approximation of the curve you will get.

  • So this is the way i solved the problem using a compromise. Since i was planing only to use full, half or quarter circles i did the following:

    Calculate Quadratic B?zier movment between point a, b and c (b is the control handle)

    x = (a.X*(1-t)^2 + b.X*2*(1-t)*t + c.X*t^2)

    y = (a.Y*(1-t)^2 + b.Y*2*(1-t)*t + c.Y*t^2)

    Calculate t for each frame while less than 1

    t = (obj.speed * dt) /((abs(a.X - c.X) * 2) * pi * (90/360))

    So far it seem to work really nice but i had to make a compromise because calculating the length of a more complex B?zier curve is way beyond my math knowledge. This is something that might bite me in the ass later if i decide to implement more complex enemy paths. We will see... ^^

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)