I'll show you two ways: The realistic way and the easy way.
REALISTIC WAY:First, you need to know what your scale is so you can convert. I'll make a random scale based on a 640x480 game, where every pixel=1 foot, which is an unlikely scale but good for a start. For this example, i will assume you are using 30 fps for the game speed;
Create a variable to hold the acceleration multiplier, just make it an actor variable, real, here we'll name it accel;
Create a global, real, called scale; You'll use this to adjust for the size of the game. Since our scale is 1:1 here, we'll just initialize scale at 1.
Create a global, real, called tvelocity; This is our terminal velocity, which for a human falling with no parachute, on planet earth, is 124 miles per hour. that's 5,280 * 124 divided by 3600 seconds, or 181 ft/s. So initialize tvelocity at 181*scale.
So we have a screen that's 640 feet wide and 480 feet high.
We'll accelerate 32 pixels every 30 frames, a ratio of approximately 1.07:1.
So every frame, we'll increase our multiplier by 1.07*scale (which for now is 1).
So in Actor>DrawActor>ScriptEditor>
- Code: Select all
if(yvelocity<tvelocity){
accel+=1.07*scale;}
yvelocity+=accel;
The player continues to fall, but only gets faster until tvelocity is reached.
If you want 4 pixels to equal 1 foot, then you'd have a scale of 4, and it would adjust correctly.
Now you'll find that this is waaaaaaaay too fast, and that's just something you'll have to deal with as most programmers do at one time or another.
EASY WAY:if(yvelocity<20){
yvelocity+=1 }