Constant speed through Bézier curve?

Get help using Construct 2

Post » Sat Aug 31, 2013 8:48 am

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:

B
7
S
2
Posts: 38
Reputation: 555

Post » Sat Aug 31, 2013 11:53 am

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 told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Sep 04, 2013 2:30 pm

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 ^^
B
7
S
2
Posts: 38
Reputation: 555

Post » Wed Sep 04, 2013 6:20 pm

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.
B
94
S
33
G
118
Posts: 5,393
Reputation: 75,847

Post » Thu Sep 05, 2013 1:45 pm

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... ^^hdnine2013-09-05 13:47:55
B
7
S
2
Posts: 38
Reputation: 555


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 9 guests