Issue attaining pixel perfect collision

S

Smidge7

Guest
Hey guys i'm new to this, I've watched many tutorials on attaining perfect pixel collision with walls but they are all based on arrow key/wasd movement and hspd/vspd variables. My issue is that my character doesn't move using these methods.

My obj_player has and orb (obj_dot) that orbits it and when you press the mouse button it flies in that direction using the speed value and the angle between the obj_player and the obj_dot.

Code:
// Player Movement

if (mouse_check_button(mb_left)) && speed = 0
{
    direction = point_direction(x,y,obj_dot.x,obj_dot.y);
    speed = 16;

}
The player keeps flying until it hits a wall with a collision event where it sets speed = 0.
This causes the player to sometimes stop just short of the wall or just inside the wall due to the speed value not being incredibly slow.

Is there a way to achieve the same movement using 'hspd/vspd' instead of 'speed'? If so i'm confident I can achieve perfect collision with the walls the same way you would with an arrow key set up. Is there a better way i'm missing?

Thanks
 
Code:
x += lengthdir_x(spd,dir);
y += lengthdir_y(spd,dir);
That will move your orb "spd" pixels in "dir" direction every step.
 

CMAllen

Member
Out of curiosity, does the collision event result in a change to the object's collision mask? It's very easy to overlook that.
 
S

Smidge7

Guest
Code:
x += lengthdir_x(spd,dir);
y += lengthdir_y(spd,dir);
That will move your orb "spd" pixels in "dir" direction every step.
So Iv'e done this and it now only moves the 'spd' pixels once and then stops again so in my case only 16 pixels.

Code:
if (mouse_check_button(mb_left)) && spd = 0
{
    spd = 16
    dir = point_direction(x,y,obj_dot.x,obj_dot.y);
    x += lengthdir_x(spd,dir);
    y += lengthdir_y(spd,dir);

}
I'd like it to continue moving that direction in a straight line until a wall is hit but its only moving 1 step when I click and then not moving as the spd = 16 and a collision with a wall would set it back to 0.

Sorry if this doesn't make sense as I said i'm new
 
S

Smidge7

Guest
Out of curiosity, does the collision event result in a change to the object's collision mask? It's very easy to overlook that.
No it does not. If I understand you correctly you're saying that if my collision mask becomes smaller once I hit the wall then it would appear that I am a little too far away from it? However that's not the case, the masks remain the same size/shape and sometimes it does stop at the correct pixel like I want but sometimes there is a 3-4 pixel discrepancy away from/into the wall due to the objects speed.
 

CMAllen

Member
Well, you're wanting pixel perfect collisions, and that means using pixel-based collision masks. Therein, if your sprite changes on collision, the mask changes with it.
 
if (mouse_check_button(mb_left)) && spd = 0 { spd = 16 dir = point_direction(x,y,obj_dot.x,obj_dot.y); x += lengthdir_x(spd,dir); y += lengthdir_y(spd,dir); }
You're checking if the spd == 0 and then setting the spd to 16, which means the code in the if statement will only run once.

Also, if you're doing a comparison (does this equal that) you should always use ==. Single = is for setting something to something else, Double == is for checking if something equals something else.

This might be what you want to do.

Step event:
Code:
if (mouse_check_button(mb_left) == true) {
   var dir = point_direction(x,y,obj_dot.x,obj_dot.y);
   x += lengthdir_x(16,dir);
   y += lengthdir_y(16,dir);
}
If you want to use the spd variable, you will have to set spd = 16 in the CREATE event and then use the above code with only the 16 replaced with spd.
 
Top