How do I spawn the same object with a differnt angle

0 favourites
  • 4 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • I'm trying to experiment a bit with construct 2 and I got stuck while trying to emulate some of my favorite run and gun patterns.

    I want to create the same object every tick and every time it spawns it spawns with a different angle (from 1 - 360).

    I have a every tick event rasing a variable by 1; once it reaches 360 the variable gets reset to 1;

    -and here comes my problem-

    I spawn the object every 0.1 sec and If I try to set his angle equal to the variable above every istance of this object gets that variable.

    Any way to set the angle to the newest created istance of an object?

  • maybe add an instance variable of the objects =0, and every tick with also condition IF the instance variable =0, on the action after set the angle the instance variable go to 1

  • Hey diamantico21!

    If you adjust the angle right after the spawn action, it will automatically apply to the last spawned object only.

    See this capx: https://www.dropbox.com/s/wzylu65g7jhu6 ... .capx?dl=0

    I'm using the amount of sprites to determine the angle, but if you really prefer a variable, I suggest you set it to the remainder of the new value, so you don't have to adjust it everytime it gets to 361.

    For instance:

    currentAngle = 0
    Every 0.1 seconds
       Spawn Sprite
       Set angle to currentAngle
       Set currentAngle to (currentAngle + 1) % 360
    [/code:2gu4vy3n]
    
    [EDIT] It seems your specific problem is you're using two different events for adjusting the variable and spwaning the objects. They should be both inside the same event, like above.
    
    Hope this helps. Cheers!
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hey diamantico21!

    If you adjust the angle right after the spawn action, it will automatically apply to the last spawned object only.

    See this capx: https://www.dropbox.com/s/wzylu65g7jhu6 ... .capx?dl=0

    I'm using the amount of sprites to determine the angle, but if you really prefer a variable, I suggest you set it to the remainder of the new value, so you don't have to adjust it everytime it gets to 361.

    For instance:

    > currentAngle = 0
    Evry 0.1 seconds
       Spawn Sprite
       Set angle to currentAngle
       Set currentAngle to (currentAngle + 1) % 360
    [/code:38vwdmx5]
    
    [EDIT] It seems your specific problem is you're using two different events for adjusting the variable and spwaning the objects. They should be both inside the same event, like above.
    
    Hope this helps. Cheers!
    

    Thank you.

    I never knew that the set angle event works just with the last spawned object and since I had other events going between the spawn and the set angle event it didn't actually work as intended.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)