Circular collision

Discussion in 'Programming' started by Gabriel Fournier, Oct 14, 2016.

Tags:
  1. Gabriel Fournier

    Gabriel Fournier Member

    Joined:
    Jul 5, 2016
    Posts:
    31
    Hi everyone,

    I'm trying to make a pixel perfect circular collision. I want to restricred a circular zone around a player so he cannot go out of this circular zone.

    I know there is a collision_circle in game maker but I' m not sure it's good for me ..

    Is there smeone who can help me with this?
     
  2. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,382
    You could use that but .... actually what might be the easiest thing for you is something like this in your End Step event...

    if distance_to_point(x,y) > some_number
    {
    x=xprevious
    y=yprevious
    }

    Let me know if that doesn't suit your needs.
     
  3. Gabriel Fournier

    Gabriel Fournier Member

    Joined:
    Jul 5, 2016
    Posts:
    31
    I'll try this and come back to you.

    In the end what I'm trying to do is like in Arc the lad twilight of spirit movement system in battle.

    Their moving zone are delimeted by circle zone so I need to do circle collision around the player in du time
     
  4. Gabriel Fournier

    Gabriel Fournier Member

    Joined:
    Jul 5, 2016
    Posts:
    31
    I tweak a little bit what you gave me.

    In the end step of the player i've put

    if point_in_circle(x, y, circle.x, circle.y, 128){
    x = xprevious
    y = yprevious
    }

    It work well the only problem now is it not as fluid as I would like for the collision. I think it's because of the mask of my player probably ... ??
     
  5. RujiK

    RujiK Member

    Joined:
    Jun 21, 2016
    Posts:
    155
    I made a circle collision thing awhile ago:

    WARNING! This is DANGEROUSLY silky smooth. Try it and be amazed.

    Code:
    var distx = x - circle.x;
    var disty = y - circle.y;
    
    var max_distance = 70;
    var current_angle = point_direction(0,0,distx,disty);
    
    var max_distx = lengthdir_x(max_distance,current_angle);
    var max_disty = lengthdir_y(max_distance,current_angle);
    
    if abs(distx) > abs(max_distx) {x += max_distx - distx;}
    if abs(disty) > abs(max_disty) {y += max_disty - disty;} 
     
    SnotWaffle Studios, Negastar and Yal like this.
  6. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,453
    Nah, it's because you stop movement completely if you'd move out of the circle, even in cases where you'd slide along the edges. @RujiK's code should do exactly what you want if you modify it a bit (change max_distance to 128).
     
    RujiK likes this.
  7. Gabriel Fournier

    Gabriel Fournier Member

    Joined:
    Jul 5, 2016
    Posts:
    31
    WOW it's like magic in my eyes.

    This is EXACTLY what I wanted.

    Thank you very much
     
    RujiK and SnotWaffle Studios like this.
  8. Gabriel Fournier

    Gabriel Fournier Member

    Joined:
    Jul 5, 2016
    Posts:
    31
    Oh right now I understand but Yes @RujiK code works damn well thnaks for the feed back
     
    RujiK likes this.
  9. Negastar

    Negastar Member

    Joined:
    Aug 26, 2016
    Posts:
    24
    Looks like something I could use also. Can the script be used to check for collisions within a certain section of the circle? I'm thinking it's possible.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice