
[ad_1]
My answer involves the use of GameMaker’s Physics Engine, which may not be the right answer for everyone.
To initiate the physics system:
1) check the “use physics” check-box for all relevant object, including the ship and the ground, which can be built from rectangular box(es).
2) check the “use physics” option in all relevant rooms.
3) adjust the gravity to the desired amount in the room setting.
4) assign sprites to all physical objects, and in the object menu, create a suitable physics fixture.
The ways in which the questioner’s requirements can be fulfilled:
1)Gravity and terminal velocity: These can be fulfilled first by the automatic acceleration created by the gravity setting. Terminal velocity can be achieved by this code:
if phy_speed_y>10
{
phy_speed_y=10
}
where 10 is the terminal velocity you allow.
2)Thruster: draw your ship with the sprite pointing to the right. Do these in your “w-pressed” event:
NetForce=10
XForce=NetForce*cos(degtorad(image_angle))
YForce=-NetForce*sin(degtorad(image_angle))
physics_apply_force (x,y,XForce,YForce)
This will apply a force to the ship, or whatever is running this code from its origin point, if you want to be more sophisticated, you can replace the “x” and “y” in the “physics_apply_force” command with a specific point (like the thruster’s coordinate)
3)adjusting current direction:
Without physics: simply add or subtract from your image angle with your key presses, except you need to run this code at the end of every step:
phy_rotation=-image angle
With physics:
physics_apply_torque(10)
where “10” is replaced by the desired amount of torque. I believe negative torque turns you clockwise.
4) Land on surfaces:
if you do not have very many objects, in the events for the ship and the ground, add this event: “collision”. when you add this, the system will ask you which object do you want the current object to collide with, choose “ship” is you are doing ground, choose “ground” if you are doing ship. Then, add some placeholder scripts in the collision events so game maker doesn’t automatically delete them as empty events.
If your ship has the right geometry, it should be possible to make it land like a normal object would. If you want to make sure that it has landed on the proper side, simply check the angle it is pointing at when it lands on the place where you want it to be.
If you are dealing with many colliding objects, create a parent object and add a collision event to it, with itself.
[ad_2]