TomOmNom
Member
So I've been messing around in GMS 2.3 and have employed the use of tags in a collision system, where I can search for any asset with the tag "wall" and collide with it. Unfortunately, this has somewhat buggy results.
GML:
#region Controls
controls = {
up : keyboard_check(vk_up),
down : keyboard_check(vk_down),
right : keyboard_check(vk_right),
left : keyboard_check(vk_left)
}
#endregion Controls
hInput = (controls.right - controls.left);
vInput = (controls.down - controls.up);
if hInput = 0 && vInput = 0
{
hsp = 0;
vsp = 0;
} else {
dir = point_direction(0,0,hInput,vInput);
hsp = lengthdir_x(stats.msp, dir);
vsp = lengthdir_y(stats.msp, dir);
}
wallArray = tag_get_assets("wall");
for (i = 0; i < array_length(wallArray);i++)
{
collisionTarget = asset_get_index(wallArray[i]);
if place_meeting(x+hsp,y,collisionTarget)
{
while !place_meeting(x+sign(hsp),y,collisionTarget) x += sign(hsp);
hsp = 0;
}
if place_meeting(x,y+vsp,collisionTarget)
{
while !place_meeting(x,y+sign(vsp),collisionTarget) y += sign(vsp);
vsp = 0;
}
}
x += hsp;
y += vsp;
I've attached an image of how the player and wall objects often collide at corners.
Attachments
-
266 bytes Views: 1