Reputation: 309
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
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