woensdag 25 januari 2012
Flying pickups
Dear readers,
For one of our new games we have flying pickups which move towards the player when an enemy is killed. The kind of movement we want is shown in the image below.
What's important about this movement is that it has a nice curve to it. The problem here is: how do we get this curve given that the starting and end position of the curve are different each time because they depend on where the player and the enemy are. Also the maximum height of the curve should be easy to change.
I've split the problem into two components: movement of point A to point B on the XZ coordinates and the movement on the Y coordinate as can be seen in the images below.
As you can see the movement in XZ coordinates is a simple line segment (linear interpolation between A and B).
The movement in Y coordinates is however not as simple (the height of the end point B happens to be fixed at 0.5). But this curve looks oddly familiar. Indeed, in (one of my earlier blog posts) I wrote about how Pieter needed a function with certain properties. Now a few months later it seems I need a similar kind of function, just a little but more dynamic as the height of the curve is now a variable as well as the starting point Ay. Again we want to find the a, b and c coefficients of the second degree polynomial f(x) = ax^2 + bx + c. So we go back to pen and paper and calculate a, b and c as a function of H and Ay (and t which is the point where f(t) = H). Here's a photo of the calculations, they're similar to the calculations I described in the earlier blog post.
Calculating the a, b and c coefficient of the second degree polynomial function.
Also a minor correction on our previous blogpost: if you want to see the flying souls move up, you need to scroll the texture (UV coordinates) down and not up. Otherwise the flying souls move down into the ground.
-- Stijn
Abonneren op:
Reacties posten (Atom)
Geen opmerkingen:
Een reactie posten