How to get a better randomization

braverybravery Member, PRO Posts: 35
Hello,

I have a fly that throght bombs on my player and I want the bombs to be near explod almost near my player place, so I add the the bombs an Accelerate Toward action, and in the filed "accelerate toward the point" I add the following expression:
game.PlayerX + random(-200,200)
where game.PlayerX is the current player x position.

However the problem is that the bombs is almost hit the player and very rare bombs explode beside it, so how can I make this random operation happen better, where what I want is most of the time the bombs explode beside the player (either in front of player or back of the player) and rare bombs hit him directly.

Please advise.

Comments

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Randomize the speed in the accelerate behavior as well and you can randomize the drag as well.
  • braverybravery Member, PRO Posts: 35
    That do paritially help, but still the accuracy of the drop is very high

    Can anyone help more about that?
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Also remember the actor's position is based on it's center so take away some of the value from the position X. So if the character is 100 pixels wide from the edge of the actor to the X position would be 50 pixels. Shorten that and you could also include the distance of the bombs size to it's position.

    (Game.player.X - 30) + random(-200,200)

    Increase or decrease the -30 until you get what you want.
  • braverybravery Member, PRO Posts: 35
    Thanks for the help, actually I have a different idea, but what I want to ask know:

    is there a way to say something like:
    if(random(1,3)=1) then
    do
    ....
    else
    ....

    The problem is that I can't set a random function inside a condition so can you tell me how should I do this?

    Thanks
  • SocksSocks London, UK.Member Posts: 12,822
    Thanks for the help, actually I have a different idea, but what I want to ask know:

    is there a way to say something like:
    if(random(1,3)=1) then
    do
    ....
    else
    ....

    The problem is that I can't set a random function inside a condition so can you tell me how should I do this?

    Thanks
    Make an attribute, integer, value 1.

    If attribute = random (1,3) [then do some stuff]
  • braverybravery Member, PRO Posts: 35
    wow good and nice idea thank you
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Yes a much easier way is to make a group of preset landing distances and randomize based on the method you chose.
Sign In or Register to comment.