Spawn items along a designated track

0 favourites
  • 6 posts
From the Asset Store
Simple and easily editable template for a dynamic camera that zooms in and out based on how far apart the players are.
  • Hi there,

    is there a way to randomly spawn an item every X seconds within a certain area?

    I have a top down racer, so I want power ups to appear randomly along the track.

    Thanks!!

    Andy

  • Thanks - but that will spawn anywhere on the screen don’t it?

    I need to endure they spawn along my race track, which is full of twists and turns.

    Apologies if I didn’t explain myself

  • Here's one possible solution.

    Create a new sprite, and place it at the start of your track. Also set it's initial visibility to invisible. The idea is you'll place instances of this object around the track like a dotted line along the shape of the track. For simplicity you should create the instances as you go around the track so they'll be in order for event purposes.

    global number i=0
    global number t=0
    
    start of layout
    repeat 10 times
    -- set i to int(random(sprite.count))
    -- set t to random(1)
    -- create tree at lerp(sprite(i).x, sprite(i+1).x, t), lerp(sprite(i).y, sprite(i+1).y, t)
    -- tree move random(-40, 40) pixels at angle 90+angle(sprite(i).x,sprite(i).y,sprite(i+1).x,sprite(i+1).y)

    dropbox.com/s/81o7e6i8qefaoec/create_along_path.capx

    It creates everything beforehand instead of only around the player, but it's part of the solution.

  • Wow thanks - but this has totally lost me!

    I think you’re right - I should create all the instances around the track with visibility set to invisible and then what I want to do is toggle the visibility of them in a random order each time there is a collision with the first one. So there are never more than one on visible at a time.

    So if I have:

    SpriteA

    SpriteB

    SpriteC

    SpriteA is visible from layout start

    When the car collides with SpriteA, randomly choose another Sprite from the list (in this example B or C) and make that visible.

    If the car collides with the new one, again, choose a random Sprite from the list to make visible next.

    Does this make sense?

    Thanks so much

    Andy

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks - but that will spawn anywhere on the screen don’t it?

    I need to endure they spawn along my race track, which is full of twists and turns.

    Apologies if I didn’t explain myself

    This is not spawn an object anywhere on the screen but at a square 100x100 px at upper left of the map.

    You can change this numbers at any time and move the square at any point of your map..

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