• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How to make player object move with sine wave platform

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
 

Yal

šŸ§ *penguin noises*
GMC Elder
For the platforms: instead of moving to the new position right away each step, compute the new Y first, then check how far it needs to move to get there - store this in a variable delta_y. Next, check if there's a player (or any other object that can ride on the platforms) in the way, or resting on top on the platforms. If so, move them delta_y. In either case, move the platform delta_y.
 
Top