N
NeZvers
Guest
I'm puzzled for some time how to solve this.
For the beginning, I'm using bitwise calculation as a challenge, but it's easily translatable to the traditional calculation (I'll provide explanation just in case).
So the problem is that when fraction return is active my character keeps sliding the floor until hits a wall.
Just in case:
For the beginning, I'm using bitwise calculation as a challenge, but it's easily translatable to the traditional calculation (I'll provide explanation just in case).
Code:
/*
hspd[0] used for main speed
hspd[1] used to carry over the fraction
RUN speed is 2<<8 = 512
Acceleration is RUN / 30
*/
/// H-collision script start
//speeds are 256 times higher since not using floats
var hsp = (bit_abs(hspd[0]) >> 8) * bit_sign(hspd[0]); // hsp is used for collision and setting x
// >>8 work similar as div 256 and floor rounding
// bit_abs and bit_sign is equal to their native gml counterpart abs() and sign()
// fraction seems to be calculated right
hspd[1] = hspd[0] - (hsp<<8); // save remainder for smooth walking
// <<8 work similar as *256
/// H-movement script start
hspd[0]+=hspd[1];
hspd[1]=0;
Just in case:
Code:
///h_move(hinput)
var Xin = argument[0];
if(!hurt && !dashing && Xin!=0){
if(btns & dash){
dashing = true; //turn off in dash state end
}
if(dashing){
if(Xin>0){
hspd[0] = DASH;
}
else{
hspd[0] = -DASH;
}
}
}
hspd[0]+=hspd[1]; //return fraction
hspd[1]=0;
if(!dashing && Xin > 0) //go right
{
facing = 1;
if(grounded)
{
if(hspd[0]>=0) //same direction
{
hspd[0] += RUN;
}
else //changing direction
{
hspd[0] += SKID;
}
}
else
{
hspd[0] += AIR;
}
}
if(!dashing && Xin <0)
{
facing = -1;
if(grounded)
{
if(hspd[0]<=0) //same direction
{
hspd[0] -= RUN;
}
else //changing direction
{
hspd[0] -= SKID;
}
}
else
{
hspd[0] -= AIR;
}
}
if(!dashing && Xin == 0) //released direction
{
if(grounded)
{
hspd[0] = bit_approach(hspd[0], 0, DRAG); //slow down
}
else
{
hspd[0] = bit_approach(hspd[0], 0, AIRS); //slow down
}
}
if(!dashing){
if(hspd[0] > MAX){hspd[0] = MAX;} //clamp
if(hspd[0] < -MAX){hspd[0] = -MAX;} //clamp
}
else{
if(hspd[0] > DASH){hspd[0] = DASH;} //clamp
if(hspd[0] < -DASH){hspd[0] = -DASH;} //clamp
}