C
circledata
Guest
Hey all, I'm currently creating my first-ever game with GameMaker (v2.3.0.529), and have encountered a pretty tough problem (for me, at least).
The game I'm making is going to be fairly simple - the player will take control of a car and try to hit moving targets. I've just arrived at the point where I'm going to need collision (as I've finished player/target movement), but I'm running into issues actually figuring out how to do this, and it comes down to how the player can/does move. I'm using fairly standard vehicle controls where W = Accelerate, S = Decelerate, A = Turn Left, and D = Turn Right.
All I want to do right now is get the player to collide with a set of walls surrounding it (basically, I just want it to collide with the edges of the screen for now). The walls are made up of objects which are solid - the car is solid as well. I don't need the collision to be realistic, I just need it to "feel" fairly normal. I've searched around on forums for solutions to this problem, but nothing I've found works with my movement controls ("works" in this instance meaning "doesn't make the player phase through walls depending on the angle they come in on / if they are moving forwards or backwards / etcetera). Any and all help is greatly appreciated!
Below is the movement code for my player object, in the "step" event. I understand that it may aid in figuring out what exactly I need to do to use the right code for the right parts of the collision:
The game I'm making is going to be fairly simple - the player will take control of a car and try to hit moving targets. I've just arrived at the point where I'm going to need collision (as I've finished player/target movement), but I'm running into issues actually figuring out how to do this, and it comes down to how the player can/does move. I'm using fairly standard vehicle controls where W = Accelerate, S = Decelerate, A = Turn Left, and D = Turn Right.
All I want to do right now is get the player to collide with a set of walls surrounding it (basically, I just want it to collide with the edges of the screen for now). The walls are made up of objects which are solid - the car is solid as well. I don't need the collision to be realistic, I just need it to "feel" fairly normal. I've searched around on forums for solutions to this problem, but nothing I've found works with my movement controls ("works" in this instance meaning "doesn't make the player phase through walls depending on the angle they come in on / if they are moving forwards or backwards / etcetera). Any and all help is greatly appreciated!
Below is the movement code for my player object, in the "step" event. I understand that it may aid in figuring out what exactly I need to do to use the right code for the right parts of the collision:
GML:
input_x = keyboard_check(R_BTN) - keyboard_check(L_BTN);
input_y = keyboard_check(D_BTN) - keyboard_check(U_BTN);
if (input_x != 0) {
if(abs(speed) > 0) {
dir -= DIR_STEP * input_x;
if (dir < 0) {
dir += 360;
}
while (dir > 360) {
dir -= 360;
}
show_debug_message(dir);
image_angle = dir;
friction += DECAY_CONST;
}
}
if (input_y != 0) {
motion_add(dir, MOVE_CONST * (input_y * (-1)));
if (speed > MAX_MOVE * sign(speed)) {speed = MAX_MOVE * sign(speed)};
}
else {
if(abs(speed) > 0) {
friction += DECAY_CONST;
}
}
Last edited by a moderator: