set random angle with exclusion

0 favourites
  • 11 posts
From the Asset Store
3D Car Pack 1
$2.99 USD
3D models + Rendered Low-Poly Cars in isometric, top-down, and side angles.
  • Here's what i have.

    Event 4 is checking if newly created sprite angle is equal to the previous sprites angle. If both angles are equal then it sets new angle for new sprite.

    Example:

    If first sprites angle is equal 90 then second sprite is set to random(angle), but this random(angle) for second sprite can produce angle equal to 90 as well.

    How can I prevent this?

  • You could try choose(random(0,firstangle - t),random(firstangle + t, 360)

    Where 't' is your tolerance.

    This should work, I have not tested it. But you can see what I mean.

  • Thanks for answer sqiddster it should work but it's not :/

    floor(choose(random(0,Last_Left_Angle-90)/90,random(Last_Left_Angle+90, 360)/90))*90

    if Last_Left_Angle = 90

    then choose(random(0,0)/90, random(180,360)/90)*90

    • choose(0,[2 or 3 or 4])*90
    • will give 0, 180, 270, 360 - correct

    if Last_Left_Angle = 180

    then choose(random(0,90)/90, random(270,360)/90)*90

    • choose([0 or 1], [3 or 4])*90
    • will give 0, 90, 270, 360 - correct

    but sprites still are on the same angles :/

  • OK, I had a look at your capx.

    All you need to do is store a global variable last_angle.

    if last_angle = 90 then set angle to choose(0,180,270)

    if last_angle = 0 then set angle to choose(90,180,270)

    etc.

    This is not the most elegant solution, but I am sick ;)

  • haha yeah, it's a harsh solution but will do for now ;)

    get well sqiddster :)

  • I feel bad for implementing such a brute solution... perhaps when my cognitive functions increase :D

  • <img src="http://dl.dropbox.com/u/34375299/Construct%202/issues/random%20angle.jpg" border="0" />

    still wrong,I'm really missing something obvious here.

  • Your code is weird. On creation you directly set a random angle, and then you store it in Last_Left_Angle to discard it afterward... What is the point? It will still look like a basic choose(0,90,180,270)

    But I think I understand what you want to do, I would do it like that:

    Global number Last_Left_Angle=-1 // no discarding at start
    +TrenchTile: Wall = "Left"
    +TrenchTile: Pick nearest to (0,0)
    +TrenchTile: Y > 60
      Local choice = ""  // to store the possible angles 0,1,2,3 * 90
      +System: repeat 4 times
      +System: loopindex is not equal to Last_Left_Angle
        -> System: set choice to (choice = "") ? loopindex : ","&loopindex
      -> System: Create object TrenchTile on layer "Tiles Front" at (Left_Wall+Wall_Move, TrenchTile.Y-TrenchTile.Height)
      -> System: set Last_Left_Angle to floor(random(4))
      -> TrenchTile: set angle to Last_Left_Angle*90
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • n creation you directly set a random angle, and then you store it in Last_Left_Angle to discard it afterward

    Yann Yes i know... I was playing with that stuff trying different solutions.

    I've tried your code but it still gives me same thing. Newly created sprite still can have angle from previous one.

  • yeah I was too tired I guess

    You can notice that I didn't even use the "choice" variable I built

    And I also made a mistake building this variable

    Global number Last_Left_Angle=-1 // no discarding at start
    +TrenchTile: Wall = "Left"
    +TrenchTile: Pick nearest to (0,0)
    +TrenchTile: Y > 60
      Local choice = ""  // to store the possible angles 0,1,2,3 * 90
      +System: repeat 4 times
      +System: loopindex is not equal to Last_Left_Angle
        -> System: set choice to (choice = "") ? loopindex : choice&","&loopindex
      -> System: Create object TrenchTile on layer "Tiles Front" at (Left_Wall+Wall_Move, TrenchTile.Y-TrenchTile.Height)
      -> System: set Last_Left_Angle to int(tokenat(choice,floor(random(tokenCount(choice,","))),","))
      -> TrenchTile: set angle to Last_Left_Angle*90[/code:1bw4a28f]
    
    with an example
    [url=https://app.box.com/s/5jdruw05v9s4z5od8sik]randomWithExclusion.capx[/url]
  • Now it's perfect, thanks I've learned events...again :)

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