problem with random

I want one of my actors to shoot an arrow randomly. Every shot should be after 2 seconds from the previous shot, but no later than 8 seconds later. So I put a rule in: after random(2,8) seconds (run to completion), spawn the arrow and shoot.

I want it to be a random number of seconds every time. But what happens is it chooses a random number of seconds, say 4, but then it regularly shoots an arrow every 4 seconds forever. How can I get it to be a random number of seconds every single time? So it would shoot after 3, then 5, then 2, and 5, 4, 8, etc.

Answers

  • SocksSocks London, UK.Member Posts: 12,822
    Generate the random number outside of the rule.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    Hi @whompy A more detailed explanation: the Every in the Timer isn't constrainable as such, so you need to retrigger the random rule a different way. So try something like:

    Rule: When BooleanTrigger is false
    Change Attribute ShotTime to random(2,8)
    Timer: After ShotTime seconds Spawn arrow
    Shoot rule
    ---nested in timer: --- Change Attribute BooleanTrigger to true

    ----

    Rule: When BooleanTrigger is true
    Change Attribute BooleanTrigger to false

    ----------

    @Socks : "Findus" haha! (Don't tell me, you did that days ago and I'm the last one to see it!)

    "Neighbours, Everybody needs good neighbours...." :-)
  • SocksSocks London, UK.Member Posts: 12,822


    @Socks : "Findus" haha! (Don't tell me, you did that days ago and I'm the last one to see it!)

    "Neighbours, Everybody needs good neighbours...." :-)
    I don't know what you mean, that's always been my avatar. ;) :D
  • whompywhompy Member Posts: 27
    Thanks for your help guys, I'm still working on it.
  • epicstagepicstag PRO Posts: 132
    edited February 2013
    Nevermind, figured it out.
Sign In or Register to comment.