H
Hoccuspoccus
Guest
I have been using code below for moving platforms, now I would like to implement that code so that when my player is on the platform the player object moves with the platform. I know an easy way to do moving platforms is just horizontal speed = direction * movement speed; and then you add the speed of the platform to your player object speed if you are standing on the platform. Obviously the sine wave method is a lot smoother and practical than the easy way, so any tips how to do this with the sine wave method?
Code:
Create:
t = 0;
increment = 12; //degrees -- freq = 1 oscillation per second (1Hz) in a 30 fps room
amplitude = 10; //pixels of peak oscillation
//clone the y-position (or use x instead if you're doing horizontal oscillation)
yy = y;
Step:
t = (t + increment) mod 360;
shift = amplitude * dsin(t);
//clone the movement from the object's speed and direction
yy += vspeed;
y = yy + shift; //vertical wave motion