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:
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.
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;
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.