R
Reaxgrim
Guest
Ok. am new to gm2 and gml altogether.
But was going along with how gm_wolf does his tileset collision and came across a slight problem.
I am using a 16x16 collision tileset.
basically if falling from a decent height or just randomly when jumping around like a madman my little guy goes straight through the collision tileset.
I am thinking that its not detecting the collision fast enough?
gif of problem below. and the code. (ps: sorry if my codes a mess as i said. new to gml)
And the code.
CREATE ------
STEP -----
Any ideas/thought would be great.
Cheers
- Reax.
But was going along with how gm_wolf does his tileset collision and came across a slight problem.
I am using a 16x16 collision tileset.
basically if falling from a decent height or just randomly when jumping around like a madman my little guy goes straight through the collision tileset.
I am thinking that its not detecting the collision fast enough?
gif of problem below. and the code. (ps: sorry if my codes a mess as i said. new to gml)
And the code.
CREATE ------
Code:
cursor_sprite = spr_cursoro;
window_set_cursor(cr_none);
//Player Camera creation
//Build Player Camera Defaults
camera = camera_create_view(0, 0, 1152, 648, 0, -1, -1, -1, 700, 700);
//Set view0 to use the camera "camera"
view_set_camera(0, camera);
//Setting up object target information
camera_set_view_target(camera,obj_Player);
camera_set_view_speed(view_camera[0], -1, -1);
camera_set_view_border(view_camera[0], 700, 700);
//Basic Player Vars
move_speed = 5;
jump_impulse = 11;
can_djump = false;
grav = 0.75;
v_speed = 0;
//Tilemap Info
var c1 = layer_get_id("collision_layer");
tilemap = layer_tilemap_get_id(c1);
//Sprite Info
sprite_bbox_left = sprite_get_bbox_left(sprite_index) - sprite_get_xoffset(sprite_index);
sprite_bbox_right = sprite_get_bbox_right(sprite_index) - sprite_get_xoffset(sprite_index);
sprite_bbox_bottom = sprite_get_bbox_bottom(sprite_index) - sprite_get_yoffset(sprite_index);
sprite_bbox_top = sprite_get_bbox_top(sprite_index) - sprite_get_yoffset(sprite_index);
STEP -----
Code:
// Jump Impulse, Top Collision Check
// Contact Points
var t1 = tilemap_get_at_pixel(tilemap,bbox_left,bbox_bottom + 1)& tile_index_mask;
var t2 = tilemap_get_at_pixel(tilemap,bbox_right,bbox_bottom + 1)& tile_index_mask;
//Tile ID checking
if (t1 != 0 || t2 != 0) {
if (keyboard_check_pressed(vk_space)) {
v_speed = -jump_impulse;
can_djump = true;
}
} else {
if (keyboard_check_pressed(vk_space) & can_djump != false) {
v_speed = -jump_impulse;
can_djump = false;
}
}
var dx = move_speed * (keyboard_check(ord("D")) - keyboard_check(ord("A")));
var dy = v_speed;
v_speed += grav;
if (keyboard_check(ord("D"))) {
image_xscale = 1;
} else if (keyboard_check(ord("A"))) {
image_xscale = -1;
}
// Vertical Move, Bottom Collision Check
y += dy;
if (dy > 0) {
// Contact Points
var t1 = tilemap_get_at_pixel(tilemap, bbox_left, bbox_bottom) & tile_index_mask;
var t2 = tilemap_get_at_pixel(tilemap, bbox_right, bbox_bottom) & tile_index_mask;
//Tile ID checking
if (t1 == 1 || t2 == 1) {
y = ((bbox_bottom & ~15) - 1) - sprite_bbox_bottom;
v_speed = 0;
}
} else {
// Contact Points
var t1 = tilemap_get_at_pixel(tilemap, bbox_left, bbox_top) & tile_index_mask;
var t2 = tilemap_get_at_pixel(tilemap, bbox_right,bbox_top) & tile_index_mask;
//Tile ID checking
if (t1 == 1 || t2 == 1) {
y = ((bbox_top + 16) & ~15) - sprite_bbox_top;
v_speed = 0;
}
}
// Horizontal Movement, Left/Right Collision Check
x += dx;
if (dx > 0) { // Right Move
sprite_index = spr_Bloo;
// Contact Points
var t1 = tilemap_get_at_pixel(tilemap, bbox_right, bbox_top) & tile_index_mask;
var t2 = tilemap_get_at_pixel(tilemap, bbox_right,bbox_bottom) & tile_index_mask;
//Tile ID checking
if (t1 == 1 || t2 == 1) {
x = ((bbox_right & ~15) - 1) - sprite_bbox_right;
}
} else if (dx == 0) {
sprite_index = spr_Bloo_Idle;
}
else { // Left Move
sprite_index = spr_Bloo;
// Contact Points
var t1 = tilemap_get_at_pixel(tilemap, bbox_left, bbox_top) & tile_index_mask;
var t2 = tilemap_get_at_pixel(tilemap, bbox_left,bbox_bottom) & tile_index_mask;
//Tile ID checking
if (t1 == 1 || t2 == 1) {
x = ((bbox_left + 16) & ~15) - sprite_bbox_left;
}
}
Any ideas/thought would be great.
Cheers
- Reax.