Random timer for spawning different actors

saad1993saad1993 Member, BASIC Posts: 47

Hello all!

I need some help with creating random spawn timers for 4 actors in my game.
Basically, when I use the random function with spawn timers for all 4 of my actors, what happens is that one of them starts spawning way too much. For example, if the min value in seconds for the random spawn timer in actor A is 0.9 and in actor B it is 1. Actor A will spawn too much and too quick.

I want to figure out the best way to randomly time the spawning of actors while now allowing them to overlap too much.

Thanks!

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    If you use the random function in a 'Every' timer - it simply takes the first random value it generates and uses that value for 'every' iteration.

    The random function produces whole numbers only, your value of 0.9 will be rounded down to 0, so the timer will produce 30 spawns a second.

    If you want to generate a 'real' (with decimal places) random value then just throw some maths into your expression.

    For example random (0,1000)/1000 will give you a random value between 0 and 1 to three decimal places (so for example 0.117 or 0.946).

  • saad1993saad1993 Member, BASIC Posts: 47

    @Socks said:
    If you use the random function in a 'Every' timer - it simply takes the first random value it generates and uses that value for 'every' iteration.

    The random function produces whole numbers only, your value of 0.9 will be rounded down to 0, so the timer will produce 30 spawns a second.

    If you want to generate a 'real' (with decimal places) random value then just throw some maths into your expression.

    For example random (0,1000)/1000 will give you a random value between 0 and 1 to three decimal places (so for example 0.117 or 0.946).

    So I suppose the problem is that it uses the first value it generates, over and over again. I used your method and threw in some math, even that looks like it is using a single value.

    How do we make the timer use different random values? would be the question.

  • IceboxIcebox Member Posts: 1,485
    edited August 2016

    You can do it with mod function and incrementing an integer value , im not sure if its a good way.

    Edit: or without incrementing an attribute, you can use self.time instead of self.spawner and use mod conditions if you want

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    @saad1993 said:
    So I suppose the problem is that it uses the first value it generates, over and over again.

    Yes, that is what 'every' means, it means 'all' iterations. I always say that it would be perfectly normal for a shop to say it was open 'every' Saturday, but it would be strange to say it's open 'every' . . and then underneath have a list of random days, in this context 'every' would make no sense,

    Hope that makes sense !

    @saad1993 said:
    I used your method and threw in some math, even that looks like it is using a single value.

    The idea of using maths to allow the random function to generate decimal values (rather than only whole values) has got nothing to do with the fact that the Timer behaviour doesn't produce a random value 'every' itteration when using a random function in the timer interval.

    The two issues are unrelated.

    How do we make the timer use different random values? would be the question.

    I do it like this (below) but there are several methods . . .

    Timer, After game.X seconds
    . . . Spawn what needs to be spawned
    . . . Change game.X to a random number
    . . . Destroy this actor
    . . . Spawn the spawner actor.

Sign In or Register to comment.