Collision

ban885

Member
I Am working on a TopDown Game, and seem to be horrible with collisions

collision event with a wall
GML:
if place_meeting(x,y,Wall)
{
x = xprevious
y = yprevious
}
tried  changing the x and y values
[CODE=gml]if place_meeting(x,+1,y+1,Wall)
{
x = xprevious
y = yprevious
}

[CODE]
if place_meeting(x-1,y-1,Wall)
{
x = xprevious
y = yprevious
}
is the closest thing i could get to without it passing through the wall but, the object gets stuck when rotating in another direction.
I have Tried changed the collision mask and messing with that but non of the results are what I wanted.

Code:
direction = point_direction(x,y,other.x,other.y)+180
^tried this works great for like enemies when they collide with other things but for some reason it doesn't work on the character lol.
////////////////////////////////////////////////////
Code:
if keyboard_check_direct(ord("W"))
   {
   move_towards_point(mouse_x,mouse_y,1)
  direction =   point_direction(x,y,mouse_x,mouse_y)
   }
^ this is what i have for a movement code

Starting to think i might need to use rectangle collision, now i am not using x or y values for speed or hspeed or vspeed.
just using the standard gml speed variable which I hear isn't good to use.

anyone have suggestions or should i probably switch and try rectangle collision.

Collision.png
 

Rob

Member
You want to be checking for your x + the_amount_of_pixels_its_trying_to_move_THIS_STEP ad the same for y.

If a collision is detected, you then use a loop to move the sign of your horizontal/vertical speed (eg -1, 0 or 1) until there is a collision 1 pixel away, and then you set horizontal/vertical speed to 0.
There are plenty of blogs/videos showing this kind of code.
 

ban885

Member
You want to be checking for your x + the_amount_of_pixels_its_trying_to_move_THIS_STEP ad the same for y.

If a collision is detected, you then use a loop to move the sign of your horizontal/vertical speed (eg -1, 0 or 1) until there is a collision 1 pixel away, and then you set horizontal/vertical speed to 0.
There are plenty of blogs/videos showing this kind of code.
Thank you :) i'll look into that!
 

ban885

Member
You want to be checking for your x + the_amount_of_pixels_its_trying_to_move_THIS_STEP ad the same for y.

If a collision is detected, you then use a loop to move the sign of your horizontal/vertical speed (eg -1, 0 or 1) until there is a collision 1 pixel away, and then you set horizontal/vertical speed to 0.
There are plenty of blogs/videos showing this kind of code.
so did manage to fix the collision clip and getting by simply messing with place empty code,
GML:
 if place_empty(x+5,y,Wall)
  {
     x+=1
    
     }
    if place_empty(x-5,y,Wall)
     {
     x-=1
     }
    
    
    if place_empty(x,y+5,Wall)
    {
    
     y+=1
    
    }
         if place_empty(x,y-5,Wall)
    {
    
     y-=1
    
    }
turns out I just had to adjust the x and y values in the place_empty
problem I was having before is that it was not colliding with the top of the block right side of the block,
had to make adjustments and figure it out and I did it ! smooth collision and no clipping i was using the rectangle collision with bbox varibles
but it didn't make sense to have it, since that I'm already checking all sides for collision for it
I get way to happy when things work. lol.
thanks for your help.
 
Top