B
bigbeno37
Guest
Over the last couple of days, I've been trying to get into Game Maker and see what I can do with it. It seems pretty cool so far, but I've read from numerous places online that using the solid tickbox for any object that does not move leads to more bad than good, and hence I stopped using it. But now, I have to program in collision handling, which is a pain.
One of my main issues is when dealing with collisions with the wall; I would like the player to be able to go right up to the wall, but when I do this, the player is able to go into the wall, but not escape from it. This is my current code:
To get around the issue of plays being able to go into the wall, I made a conditional checking to see if the player intersects with the wall within collision_check_distance units. If I make value low, then the players can move into the wall, but if I make this high, there is an invisible wall between the player and the wall.
Another issue I'm having is that when the player dashes (press SHIFT -> go 4 times the normal speed in one direction for a certain period of time), they can seemingly go past some of this barrier; even with an invisible wall between the player and the wall, if the player dashes into it, they can occasionally go further than 20 pixels (the value I'm using at the moment), which shouldn't happen. The code for the dash state can be found here:
And for my final issue, I have two enemies that constantly follow the player around. With solid collision checking, this was fine; they would collide, and continue heading in the direction of the player, without intersecting. Now, however, when the two enemies collide, they simply freeze, and do not move any further. Here is the code for the enemies:
If you want to take a look at the source code in it's entirety, it's all on github: https://github.com/bigbeno37/ROYGBIV/tree/remove-physics
And here's a link to the .exe file if you want clarification on what I'm talking about: https://drive.google.com/open?id=0BySjsjvInP0-NGtLWi1vZ0VQTVU
I apologise if all of this has been answered before. I tried taking a look, but nothing satisfactorily answered my questions.
Thank you to anybody who replies!
One of my main issues is when dealing with collisions with the wall; I would like the player to be able to go right up to the wall, but when I do this, the player is able to go into the wall, but not escape from it. This is my current code:
Code:
///scr_move_state
// Define right_key and such vars
scr_get_input();
if (dash_key and (x_axis != 0 or y_axis != 0)) {
state = scr_dash_state;
alarm[0] = room_speed/6;
}
if (white_key) {
sprite_index = spr_player_white;
}
if (black_key) {
sprite_index = spr_player_black;
}
// Get direction
dir = point_direction(0, 0, x_axis, y_axis);
// Get the length
if (x_axis == 0 and y_axis == 0) {
len = 0;
} else {
len = obj_player_speed;
}
// Get the h_speed and v_speed
var h_speed = lengthdir_x(len, dir);
var v_speed = lengthdir_y(len, dir);
var collision_check_distance = 20;
if ((up_key and !place_meeting(x, y-collision_check_distance, obj_wall)) or (down_key and !place_meeting(x, y+collision_check_distance, obj_wall))){
y += v_speed;
}
if ((right_key and !place_meeting(x+collision_check_distance, y, obj_wall)) or (left_key and !place_meeting(x-collision_check_distance, y, obj_wall))){
x += h_speed;
}
Another issue I'm having is that when the player dashes (press SHIFT -> go 4 times the normal speed in one direction for a certain period of time), they can seemingly go past some of this barrier; even with an invisible wall between the player and the wall, if the player dashes into it, they can occasionally go further than 20 pixels (the value I'm using at the moment), which shouldn't happen. The code for the dash state can be found here:
Code:
///scr_dash_state
var len = obj_player_speed*4;
// Get the h_speed and v_speed
var h_speed = lengthdir_x(len, dir);
var v_speed = lengthdir_y(len, dir);
var dash_collision_check_distance = 20;
if (place_meeting(x+dash_collision_check_distance, y, obj_wall) or place_meeting(x-dash_collision_check_distance, y, obj_wall)){
h_speed = 0;
}
if (place_meeting(x, y+dash_collision_check_distance, obj_wall) or place_meeting(x, y-dash_collision_check_distance, obj_wall)){
v_speed = 0;
}
x += h_speed;
y += v_speed;
// Create the dash effect
var dash = instance_create(x, y, obj_dash_effect);
dash.sprite_index = sprite_index;
dash.image_index = image_index;
Code:
///scr_enemy_move_state
// Get direction
var dir = point_direction(x, y, obj_player.x, obj_player.y);
var len = obj_enemy_speed;
// Get the h_speed and v_speed
var h_speed = lengthdir_x(len, dir);
var v_speed = lengthdir_y(len, dir);
var collision_check_distance = 5;
if (!place_meeting(x, y-collision_check_distance, obj_collide) or !place_meeting(x, y+collision_check_distance, obj_collide)){
y += v_speed;
}
if (!place_meeting(x+collision_check_distance, y, obj_collide) or !place_meeting(x-collision_check_distance, y, obj_collide)){
x += h_speed;
}
And here's a link to the .exe file if you want clarification on what I'm talking about: https://drive.google.com/open?id=0BySjsjvInP0-NGtLWi1vZ0VQTVU
I apologise if all of this has been answered before. I tried taking a look, but nothing satisfactorily answered my questions.
Thank you to anybody who replies!