I need to create a pogo stick that jumps across the screen in arcs. I was thinking the best way to do this would be to move it on a sin wave. If the top of the wave is 1, the ground is 0 and the bottom of the wave is -1, then every time it hits 0 I would reset the values to start the sin wave again. So instead of following the typical sin wave (0, 1, 0, -1, 0 etc) it would go 0, 1, 0, 1, 0 etc.
Unfortunately my math is pretty terrible and I've been trying for hours to develop a formula. At the moment I'm just trying to make a normal sin wave where the top half emulates a pogo stick jumping, can't seem to even get that far. The closest I have is:
m_vel.x++;
float f = PI / 30 / 2;
m_vel.y = 200 * sin(f * m_vel.x);
m_vel.y = -m_vel.y;
I need the waves to be quite narrow, and the high point to be quite high. The above formula starts off ok for the first iteration but then the waves get wider and the high and low points close in on each other. Can anyone help a math noob out?
Not sure about your math, your physics needs some brushing up! The pogo stick is an example of projectile motion and its trajectory forms a parabola, which is described by a quadratic equation.
However should you persist with the incorrect sinusoidal model: The "top half" (or positive) part of a sine wave runs from 0 to pi radians. The sine represents only the y term (height), you should not have an x term there, that simply determines the horizontal step for each point. Where you have 200, that represents the maximum height the pogo stick will reach:
height = max_height * sin( theta ) ;
where 0 <= theta <= pi, and is incremented over time. The size of the increment will be determined by the forward speed, or total jump distance.
theta_step = pi / jump_distance ;
so that by the time you have reached pi radians, you will have moved by jump_distance. During the jump instantaneous distance (and therefore the x value in a plot) will be:
distance = jump_distance / theta ;