Advertisement

How would you do this?

Started by June 06, 2003 08:32 PM
3 comments, last by Crispy 21 years, 8 months ago
I have a landscape which is essentially a 2d bezier spline. What I want to do is adopt acceleration down the slopes to add a bit of dynamics to the movement over the landscape. What I know : 1) the position of the player on the spline 2) the height of the point of the line where the player is 3) one adjacent height value on either side (calculating any extra takes up a lot of cpu cycles) 4) the height value from last frame What goes wrong : Once the player has accelerated down a slope (a) and goes up the opposite slope (b), it gains acceleration in the opposite direction. Now, if I apply movement to the player (press the movement keys in addition to the natural acceleration) so that I force the player to move up the hill and over it (c) and then release the movement key, it will swing back over the top of the hill (c) from the accumulated acceleration. A not-so-good drawing:


  c 
  /\     /
 /  \b a/
/    \_/
 
The solution : I need to reset the acceleration gained from sliding down slopes every time I move over the tip of a hill. The problem : How do I know when the player has moved over a hilltop? One way would be to keep a history of height values and if they form a pattern LGL where L is less and G is greater, set acceleration to zero, but I personally really don't like this approach (since it requires me to keep a history). Can anyone suggest a better solution based on the information presented above? Thanks, Crispy

Never do anything that is a waste of time and be prepared to wage long tedious wars over this principle - Michael O'Connor

[edited by - crispy on June 6, 2003 9:33:07 PM]
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
You said the terrain is essentially a bezier spline, right. Does that mean that you have an equation for it? If you do, just differentiate that, and check whether that equals zero. There''s yer hilltops.
You know what I never noticed before?
Advertisement
Yeah, I''m calculating it as a long series of points (a 60 point spline). However, will differentiating it give me information about whether I have gone over a hilltop - eg it isn''t a at all guaramteed that the player will actually be precisely on the hilltop at any given time...

Never do anything that is a waste of time and be prepared to wage long tedious wars over this principle - Michael O''Connor

"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
If you keep track of the derivative of the function you should be able to see when it changes sign. So when going over hilltops the derivative should change from positive to negative.
Okay thanks guys I think I''ve got it now!

Never do anything that is a waste of time and be prepared to wage long tedious wars over this principle - Michael O''Connor

"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared

This topic is closed to new replies.

Advertisement