Using qerp to dive in a curve

For questions about using Classic.

Post » Sun Nov 15, 2009 4:09 am

Hi all. I have a boss in my game who floats above the player. Simple. But I want him to be able to swoop down onto the player. Not so simple.

I THINK I need to set a cubiccurve from the boss's original location, toward where the game predicts where the player is going to be (via approximate aim or something), along the point of where the boss is in relation toward the player, and end up twice the horizontal distance it took to travel (so using a lerp to find double the distance between where the boss was original and where he hit the trough of his swooping curve). The thing is... is that there are so many variables and things that I don't really understand. :(

Here, I'll draw an example of what I want via Inkscape:

Where the blue triangle is the boss's original position, the green his dynamic position, the circle the player (or where the game approximates he's going to be), and the red triangle the place I want the boss to end up (twice the X distance from the original position of the boss to the player).

Pwetty pwease? :)
Posts: 37
Reputation: 2,827

Post » Sun Nov 15, 2009 11:07 am

[quote:34fgei33]Qarp(a, b, c, x)
Quadratic interpolation. Returns lerp(lerp(a, b, x), lerp(b, c, x), x) [/quote:34fgei33]

In your case, you want to extrapolate both X and Y position, where 'a' is the starting position, 'b' the player's predicted location and finally 'c' the ending position.
'x' would be time it takes to complete the move. At 0 it will be at starting point and at 1 it will be at ending point.


[code:34fgei33]+Is Diving = 1
> Set Boss.X to qarp(starting_x,target_x, ending_x,dive_time)
> Set Boss.Y to qarp(starting_y,target_y, ending_y,dive_time)
> Add TimeDelta to dive_time
+dive_time is equal to or greater than 1
> Set Diving to 0
> Set dive_time to 0[/code:34fgei33]

Something like that. Experiment with it!
Posts: 1,910
Reputation: 13,685

Post » Thu Nov 20, 2014 9:22 pm

really sorry to bump such an old post. but could you please make a quick example capx. please.
this is something i really need but am having trouble with.
have tried many times to get my head round it myself but to no avail :(

thanks in advance ;)
Posts: 20
Reputation: 450

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests