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

GMS 2 [Solved] Projectile location tracking

Discussion in 'Programming' started by Carcophan, Nov 10, 2019.

  1. Carcophan

    Carcophan Member

    Joined:
    Aug 4, 2019
    Posts:
    85
    Hello everyone.

    I am currently using an object for projectiles, where the step event calls: "if point_in_circle(x1, y1, x2, y2, radius) instance_destroy();".

    Problem I am now encountering is when multiple clicks occur in a short period of time.

    If the first projectile is still in the air, and the second click occurs for a second shot, the step events X2/Y2 location naturally gets updated to something new - so the first projectile will not collide with that 'old' location any longer.

    There could be 3-4-5 clicks a second, and with some of the distances/travel times, there could be maybe 10-15 items in the air at a given time. Is there some kind of queuing system for each shot, that I should use? I have spent some time searching but I am not sure which direction to go or if that is 'right'.
     
  2. the_dude_abides

    the_dude_abides Member

    Joined:
    Jun 23, 2016
    Posts:
    676
    This sounds like you are treating the "object" and not its "instances"

    Every instance of an object is a separate entity when treated properly. Taking a rough guess at your problem:

    firing object (the player?)
    mouse click (released) event:
    Code:
    var inst = instance_create(x, y, whatever is your projectile object)
    with (inst)
    {
    is_x = mouse_x;
    is_y = mouse_y;
    }
    create event (projectile):
    Code:
    is_x = undefined;
    is_y = undefined;
    Only when the projectile is created does it get a value set for 'is_x' / 'is_y'

    When the projectile is created 'inst' is set to the id of the newly created instance, and so allows control of its properties. The variables for the position are set, and control ends.

    Because 'inst' is a local variable it is forgotten by the calling object when the event ends, and so any further actions will not affect previous instances.

    Each instance then holds unique values.
     
    Carcophan likes this.
  3. Carcophan

    Carcophan Member

    Joined:
    Aug 4, 2019
    Posts:
    85
    Your suggestion was 100% spot on and successful! thank you very much for your help.
     
  4. the_dude_abides

    the_dude_abides Member

    Joined:
    Jun 23, 2016
    Posts:
    676
    You're welcome :)
     

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