Sorry if this is in the wrong place - if so please move it or let me know and i'll close the thread.
I'm making a basic 'point and click' space ship game. I followed a tutorial on Youtube (
) to get the basic movement of the ship moving towards the cursor when clicked. I want to be able to add variables such as acceleration, top speed, friction, etc so that the ship doesn't just jump from a standstill to top speed at the click of a button, and instead accelerates and reaches top speed after a certain point. So far (before any attempted acceleration mechanics) the scripts look like this:
Create > Set mouse to cursors
Create > Execute codedesx = self.x;
desy = self.y;
moving = 0;
Step > Execute codeif moving = 1{
mp_potential_step(desx,desy,1,true); // 1 denotes speed
}
Global left pressed > Execute codemoving = 1;
image_angle = point_direction(self.x,self.y,mouse_x,mouse_y);
desx = mouse_x;
desy = mouse_y;
A few months ago I experimented with a different space game in which the ship was controlled using the directional buttons as opposed to a point and click method. I managed to get acceleration and speed working with another tutorial but so far haven't managed to implement the same sort of thing into my point and click game. The scripts look like this:
Create > Execute codex_speed = 0
y_speed = 0
acc_speed = 0.5 //acceleration
max_speed = 3
speed_friction = 1 //1 = no friction
image_angle= 90
direction= 90
//Physics objects must call the parent object's create event
//to initialize physics variables. Here we are calling it
//BEFORE we initialize the player's stats because obj_moveable
//also defines S_SLOPE_SLOW for itself and we want to
//overwrite the value of it with one specifically for obj_player
event_inherited();
//Here some player stats are defined (so they can be easily
//tweaked if needed).
S_GRAVITY = 0.3; //Accel. due to gravity (pixels/step*step)
S_RUN_ACCEL = 0.6; //Accel. from running on ground (pixels/step*step)
S_RUN_FRIC = 0.6; //Friction on the ground (pixels/step*step)
S_AIR_ACCEL = 0.4; //Accel. from running in the air (pixels/step*step)
S_AIR_FRIC = 0.4; //Friction in the air (pixels/step*step)
S_JUMP_SPEED = -6;
S_DJUMP_SPEED = -4; //Double jump speed
S_MAX_H = 3; //Max horizontal speed
S_MAX_V = 8; //Max vertical speed
S_SLOPE_SLOW = 0.7; //Decceleration while climbing slopes
Step > Execute code//step event
if keyboard_check(vk_left) view_angle[0] -= 3
if keyboard_check(vk_right) view_angle
if keyboard_check(vk_left) direction += 3
if keyboard_check(vk_right) direction -= 3
if keyboard_check(vk_up) {
y_speed += lengthdir_y(acc_speed, direction)
x_speed += lengthdir_x(acc_speed, direction)
}
if keyboard_check(vk_down) {
y_speed -= lengthdir_y(acc_speed, direction)
x_speed -= lengthdir_x(acc_speed, direction)
}
if (keyboard_check(ord('X'))) {
instance_create(x, y, lazer)
}
x += x_speed
y += y_speed
x_speed *= speed_friction
y_speed *= speed_friction
image_angle[90] = direction[90]
If anyone can give me any help at all I'd appreciate it immensely. I apologise if i haven't presented my code properly I'm just not sure of the best way to format it to make it clearest for you. I'm a bit of a laymen when it comes to using GML or any other code; just looking to learn by indulging in sci-fi spaceship dogfights
If it would help (and someone can suggest a good site?) I'd happily upload the game maker files for you to check it out and get a better feel for what I'm trying to achieve.