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

Adding gravity to this custom movement and collision

NazGhuL

NazTaiL
Hi. This is very frustrating... There is something that I simply can't figure out or completly understand. I'm on this for a couple of days now. A ship use its thrust to move around. Gravity pull him down.


Here is the basic code:

Code:
//Set Direction from 0 to 359
if(Move_Left)
{
Direction += Rotation_Speed;
}
if(Move_Right)
{
Direction -= Rotation_Speed;
}

//Thrust from 0 to Thrust_Max (= 4)
if(Move_Thrust)
{
Thrust_Current += Acceleration;
}
else
{
Thrust_Current = 0;
}
Thrust_Current = clamp(Thrust_Current, 0, Thrust_Max);


//That part add a decent drifting effect.
if(Thrust_Current > 0)
{
Velocity_X = dcos(Direction) * Thrust_Current;
Velocity_Y = -dsin(Direction) * Thrust_Current;
X_Speed += sign(Velocity_X - X_Speed) * 0.05;
Y_Speed += sign(Velocity_Y - Y_Speed) * 0.05;
}


//Vertical Collision (Bounce on collision and V_speed is divided by 2.
if (place_meeting(x,y+Y_Speed,obj_parent_static))
{
Y_Speed = Y_Speed/2;

    while(!place_meeting(x,y+sign(Y_Speed),obj_parent_static))
    {
    y += sign(Y_Speed);
    }
   
Y_Speed = -Y_Speed;
}
y += Y_Speed;


//Horizontal Collision (Bounce on collision and H_speed is divided by 2.
if (place_meeting(x+X_Speed,y,obj_parent_static))
{
X_Speed = X_Speed/2;

    while(!place_meeting(x+sign(X_Speed),y,obj_parent_static))
    {
    x += sign(X_Speed);
    }
   
X_Speed = -X_Speed;
}
x += X_Speed;
Works great. I'll probably use it as it is on level 'in space'.
But I want to option to add gravity. (Down, up, left or right) But just talk about the downward gravity.
Where should I start? I tried, 2 years ago, the same thing usgin the physics engine and it works well, but I want to simplify it. Any hints will be very helpful.
 
B

bojack29

Guest
Hm. I accomplished this in my HDTDT. But i know you had issues with that. Thats quite a bit of code. Have you tried simply copying and pasting the physics of the engine I had? I know you had unusual problems with the engine but did you try copying the ships code?
 

NazGhuL

NazTaiL
No. Your collision system you use is not what i'm looking for. Your code help me to create the drifting effect without the motion_add function.
 
B

bojack29

Guest
So pretty much everything I designed but like a bouncy ball?
 
Top