1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 [SOLVED] Trying to create an aiming reticle like that of Crimsonland

Discussion in 'Programming' started by Sanctifier, Jul 2, 2019.

Tags:
  1. Sanctifier

    Sanctifier Member

    Joined:
    Aug 29, 2016
    Posts:
    22
    Hi Everyone.

    I'm working on a top down shooter that's inspired by Crimsonland. Currently I have a system where every time the weapon is fired recoil increases. For every unit of recoil, the deviation in the player's accuracy cone is widened by a single degree.

    This system is currently working as intended. However, I'm wondering how I might go about representing the currently state of accuracy with a circle that widens as recoil increases.
     

    Attached Files:

  2. JackTurbo

    JackTurbo Member

    Joined:
    Oct 19, 2016
    Posts:
    821
    Simpliest way would probably be to have the reticle with a series of sub images that widen the outer ring element. Then you could set the image_speed to zero and base the image_index off of the recoil value.

    A more complex approach would be to use draw_circle at the reticle's x/y and set the radius to be based off the recoil value.
     
  3. Sabnock

    Sabnock Member

    Joined:
    Jul 21, 2016
    Posts:
    310
    i would make a sprite of the circle at it's max size and then use draw_sprite_ext( sprite, subimg, x, y, xscale, yscale, rot, colour, alpha ); in a draw event and use the xscale, yscale to set the size.
     
  4. Sanctifier

    Sanctifier Member

    Joined:
    Aug 29, 2016
    Posts:
    22
    I could make a circle based off the recoil value, but I would also need it to adjust based on the distance between the player and the crosshair in order for it to be accurate
     
  5. Sanctifier

    Sanctifier Member

    Joined:
    Aug 29, 2016
    Posts:
    22
    Thanks everyone for the replies. I managed to solve the issue. Here's what the code looks like.

    Code:
    var mouseDist = point_distance(x, y, mouse_x, mouse_y);
    var xx1, yy1, xx2, xx2, centerOffset;
    
    xx1 = x+lengthdir_x(mouseDist, angle-accuracyOffset);
    yy1 = y+lengthdir_y(mouseDist, angle-accuracyOffset);
    xx2 = x+lengthdir_x(mouseDist, angle+accuracyOffset);
    yy2 = y+lengthdir_y(mouseDist, angle+accuracyOffset);
    
    centerOffset = point_distance(mouse_x, mouse_y, xx1, yy1);
    
    draw_set_alpha(1);
    draw_set_colour(c_black);
    draw_circle(mouse_x, mouse_y, centerOffset, true);
    draw_set_colour(c_ltgray);
    draw_set_alpha(0.1);
    //draw_triangle(x, y, xx1, yy1, xx2, yy2, false);
    draw_circle(mouse_x, mouse_y, centerOffset, false);
    
    draw_set_alpha(1);
    draw_set_colour(c_white);
    
    I created a triangle (commented out now) as a reference point. its width is determined by the offset caused by recoil and the length is determined by the distance of the cursor from the player. Then I measured the distance from one point to the cursor. Note: You can choose either point here as the difference is the same. That distance determines the radius of the circle which gives me an accurate view of the deviation of the projectiles at any distance.
     

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