Copy/Paste this code for perfect player jump with mouse acc.
Posted: Thu Feb 19, 2015 11:50 pm
Since Hblade was bored and he decided to release something..
Then I decided to do the same.. because I am bored too.
Copy/paste this code (in draw actor). It will make the player jump once if you accelerate the mouse upwards.
The code assumes that the center of the screen is the platform surface. If the player is placed above 0, it will fall down to 0 as it is powered by gravity.
You can easily condition the code to be parsed only if the player is on your specific y.. so you are free of possible failures.
For the ease of such use, you can functionize this whole code and set some arguments as a setting.
Then I decided to do the same.. because I am bored too.
Copy/paste this code (in draw actor). It will make the player jump once if you accelerate the mouse upwards.
- Code: Select all
static int timer, checksum, yprev;
double xmprevious, ymprevious;
if(++timer == 5)
{
timer = 0;
xmprevious = xmouse;
ymprevious = ymouse;
}
if(ymouse < (ymprevious-20) && !checksum)
{
if(!checksum) { checksum = 1; yprev = y; }
yvelocity = -1;
}
if(y < yprev - 100)
{
yvelocity = 1;
} else if(y >= yprev && yvelocity == 1) { yvelocity = 0; checksum = 0; }
The code assumes that the center of the screen is the platform surface. If the player is placed above 0, it will fall down to 0 as it is powered by gravity.
You can easily condition the code to be parsed only if the player is on your specific y.. so you are free of possible failures.
For the ease of such use, you can functionize this whole code and set some arguments as a setting.