1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 checking if an object has rotated around itself

Discussion in 'Programming' started by julkibr, May 24, 2019.

  1. julkibr

    julkibr Member

    Joined:
    Jan 25, 2017
    Posts:
    39
    So I want to add an effect where you have to rotate the gun around itself to reload the weapon


    Code:
    step event
    image_angle = point_direction(x, y, mouse_x, mouse_y);
    I already have all the gun rotating around the player effect but I would like to know how to measure an rotation so I could add an bullet in the chamber.Thanks in advance
     
  2. the_dude_abides

    the_dude_abides Member

    Joined:
    Jun 23, 2016
    Posts:
    707
    Hopefully I can explain this well, but you can always test it for yourself if I can't....

    If your gun is at 45 degrees, and you manually add to the image angle by another 360 degrees, it will return 405 degrees as the angle. When you just have point_direction it only uses 360, but you can go over that and still have it return the expected angle:

    500 degrees would be 140 degrees, 720 is 360 etc etc

    So you set a variable to the image angle when the reload started and hold it until the process is finished, and then just see if it's 360 degrees more than the variable being held. If it is - you know it has gone around fully, and the player has chambered the bullet.

    Once the reload is finished you will go back to pointing at the mouse, and that returns image angle measurements to the usual 360 degree range.

    pseudo code:

    Code:
    if !is_reload
    {
    image_angle = point_direction(x, y, mouse_x, mouse_y);
    start_angle = image_angle;
    }
    else
    {
    if image_angle + chosen angle diff >= start_angle + 360
    {
    // can chamber, and end process;
    image_angle = start_angle;
    is_reload = false;
    }
    else
    {
    image_angle += chosen angle diff;
    }
    }
    "chosen angle diff" is whatever amount you want to add to the rotation per step
     
    Last edited: May 24, 2019
    julkibr and Toque like this.
  3. julkibr

    julkibr Member

    Joined:
    Jan 25, 2017
    Posts:
    39
    Just got home I will try this code thanks for answering
     

Share This Page