• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

GML The character stops before reaching the wall. How can i fix this?

UberhenriK

Member
Hi everybody.
Me character stops before reaching the wall.

Probably problem is in my collision system but i don't know where exactly.

Video with problem:
Collision part of "Step" event:
GML:
if (place_meeting(bbox_left, y, Obj_WallsParentV)) {
    if (XSpeed < 0) XSpeed = 0;
}
if (place_meeting(bbox_left, y, Obj_WallsParentCLeft)) {
    if (XSpeed < 0) XSpeed = 0;
}
if (place_meeting(bbox_right, y, Obj_WallsParentV)) {
    if (XSpeed > 0) XSpeed = 0;
}
if (place_meeting(bbox_right, y, Obj_WallsParentCRight)) {
    if (XSpeed > 0) XSpeed = 0;
}

if (place_meeting(x, bbox_bottom, Obj_WallsParentH)) {
    if (YSpeed > 0) YSpeed = 0;
}
if (place_meeting(x, bbox_bottom, Obj_WallsParentCBottom)) {
    if (YSpeed > 0) YSpeed = 0;
}
if (place_meeting(x, bbox_top, Obj_WallsParentH)) {
    if (YSpeed < 0) YSpeed = 0;
}
if (place_meeting(x, bbox_top, Obj_WallsParentCTop)) {
    if (YSpeed < 0) YSpeed = 0;
}

If you need it, here is full "Step" event code:
GML:
XSpeed = 0;
YSpeed = 0;

if (keyboard_check(ord("A"))) {
    XSpeed -= PlayerSpeed;
}
if (keyboard_check(ord("D"))) {
    XSpeed += PlayerSpeed;
}
if (keyboard_check(ord("W"))) {
    YSpeed -= PlayerSpeed;
}
if (keyboard_check(ord("S"))) {
    YSpeed += PlayerSpeed;
}



if (XSpeed > 0 && YSpeed = 0) image_angle = 0;
if (XSpeed < 0 && YSpeed = 0) image_angle = 180;
if (XSpeed = 0 && YSpeed > 0) image_angle = 270;
if (XSpeed = 0 && YSpeed < 0) image_angle = 90;
if (XSpeed > 0 && YSpeed < 0) image_angle = 45;
if (XSpeed < 0 && YSpeed < 0) image_angle = 135;
if (XSpeed < 0 && YSpeed > 0) image_angle = 225;
if (XSpeed > 0 && YSpeed > 0) image_angle = 315;

if (place_meeting(bbox_left, y, Obj_WallsParentV)) {
    if (XSpeed < 0) XSpeed = 0;
}
if (place_meeting(bbox_left, y, Obj_WallsParentCLeft)) {
    if (XSpeed < 0) XSpeed = 0;
}
if (place_meeting(bbox_right, y, Obj_WallsParentV)) {
    if (XSpeed > 0) XSpeed = 0;
}
if (place_meeting(bbox_right, y, Obj_WallsParentCRight)) {
    if (XSpeed > 0) XSpeed = 0;
}

if (place_meeting(x, bbox_bottom, Obj_WallsParentH)) {
    if (YSpeed > 0) YSpeed = 0;
}
if (place_meeting(x, bbox_bottom, Obj_WallsParentCBottom)) {
    if (YSpeed > 0) YSpeed = 0;
}
if (place_meeting(x, bbox_top, Obj_WallsParentH)) {
    if (YSpeed < 0) YSpeed = 0;
}
if (place_meeting(x, bbox_top, Obj_WallsParentCTop)) {
    if (YSpeed < 0) YSpeed = 0;
}

x += XSpeed;
y += YSpeed;

if (mouse_check_button(mb_right))
    image_angle = point_direction(x,y,mouse_x,mouse_y);

if (XSpeed != 0) | (YSpeed != 0)
    sprite_index = Spr_PlayerWalk;
else
    sprite_index = Spr_PlayerIdle;

1604780330405.png

How can i fix that issue?
Thank you.
 
Last edited:

Nidoking

Member
Presuming that your XSpeed and YSpeed are normally greater than one, you need to move the instance to the point of collision. This is usually done with a for loop. Pick a random thread involving collision, and someone will have quoted exactly what you need somewhere in it.
 

TheouAegis

Member
It's because you are using image_angle. If you are going to use image_angle, you should use a circular collision.
 
Top