PDA

View Full Version : moving an object randomly


gencogluMX
01-29-2009, 07:03 PM
Hi, I am tring to make an object move across the screen randomly..I want it move up-down left or right acording to the values created..for example I want my object move between value (-5 and +5 ) whats wrong with this ? because it always moves downward ???
thanks ?


on(press)
{
dur=setInterval(kos,200);
function kos(){
var rn1=Math.floor(Math.random()*(5-10))+10;
var rn2=Math.floor(Math.random()*(5-10))+10;


_root.car._x+=rn1;
_root.car._y+=rn2;

kutu.text="..."+rn1+"..."+rn2;
}}

endergrl
01-29-2009, 07:21 PM
I think you are always ending up with a positive answer. I would use this instead to create a random numberbetween -5 and 5.

random(11)-5

gencogluMX
01-29-2009, 09:23 PM
okay.. thanks it works fine....Actually what I am after is to make the object(hero) move to any direction randomly for 3000 millisecond and pause for 2000 milliseconds and move again...
// move lany direction for 3000 ms
//stop for 2000 ms
//now move any other direction again..and so on..then I wiil use a hittest to create my simple game..but I can not figure out how to create start and pause functions...
thanks