• 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!

GML Replacement for built in speed functions?

Trace

Member
So I'm trying to make some sort of F-Zero like racing game, but I'm using the built in speed variables and functions because I don't know how to achieve what i want with custom variables, which is already bad because the built in speed variables are way too jank.
The other problem with them is that i have to main states. A normal one for normal driving and steering, and another for drifting. The main difference between the two is that the normal driving one manually sets speed and direction, while the drifting state uses motion_add to be more slippery and more like drifting.
This is where the problem comes in: Since the normal driving state manually changes direction, momentum is lost in a very unnatural way when switching states, and i also cant apply motion to the sides of the player when in the normal driving state.
So what i need is some way to replicate what i have now, except with custom variables and in a way that allows me to do more natural movement while still keeping the consistent steering of the normal driving state.
Additional Information:
-Version is GM:S 1.4.9999
Code for the regular driving state:
Code:
scrInputs(); //Nothing more than button inputs
scrMovement(); //Mostly just the physics for turning

//Turning
topturn = normalturn; //This is here because the max angle at which you can turn is different for the states
direction += angle_difference(angle_z,direction)/32; //A placeholder solution for switching from drifting to normal; very bad solution and very jank

//Accelerating
if (kGas){
    speed += (topspd-speed)/accel;
}  
if (speed > topspd) speed = topspd;

//Bounce
if (kBounce and turndir != 0){
    motion_add(angle_z+90*turndir,6); //This i used to test getting pushed to the side in the normal state
}  

//friction
if (!kGas){
   friction=fric; //friction is only there when the gas button isnt pressed for consistant movement; id need some way to add friction into the side directions in this state
}
else{
   friction=0;
}
if (turnspd != 0 and kDrift) state = states.drift;
Code for drifting (most of this is similar to the previous, but with the different phyiscs):
Code:
scrInputs();
scrMovement();

//Turning
topturn = driftspd;

//Accelerating
if (kGas){
    motion_add(angle_z,turnaccel)
    if (speed > topspd) speed = topspd;
}

//friction
if (abs(speed) > 0){
   friction=fric;
}
else{
   friction=0;
}

if (turnspd = 0 or !kDrift) state = states.normal;
I think it's good if i learn how to do this kind of stuff with custom speed variables, so help would be really appreciated. If there's anything i haven't said that you would need to help me on this, please tell me.
 
Last edited:

TheouAegis

Member
motion_add is just

hspd += cos(angle_z)*turn_accel;
vspd -= sin(angle_z)*turn_accel;

Can't give more trig lessons cuz i i tta get to work.
 

Trace

Member
Alright, i managed to replicate the normal state with custom numbers. What's still a problem though is the friction for the drifting.
 
Top