Robdogga55
Robdogga55

Reputation: 309

AS3 Add movieclip to the stage on the Y axis between two points

I am trying to add a caveman (in an android game I am making for uni) on perticular X axis which is easy but the caveman is spawning anywhere on that Y axis and I would like it to spawn just in between to points that I specify on the Y axis.

cavemanVar[2].x = 352.10;
cavemanVar[2].y = Math.random()*300;

Upvotes: 0

Views: 70

Answers (1)

Marty
Marty

Reputation: 39458

Just define the start position a plus a random value whose max would be the difference to make up b.

y = a + Math.random() * (b - a);

Visually:

--+--  <- a
  |
  |
  |    <- Math.random() * (b - a)
  |
  |
--+--  <- b

Upvotes: 2

Related Questions