-
random movement
hey, Im new at flash, but Im learn as2 :P
so my problem is that I want to spawn a ball to the middle of the screen, and want it to move with constant speed in random direction everytime its spawned. it sounds really easy, but I cant make it work...
current code Im using for the ball movement is
Code:
function setBehavior(Ball:MovieClip):Void
{
var randomAction = random(2);
switch (randomAction) {
case 0 :
Ball.xSpeed = Math.random(Ball.mySpeed)*Ball.mySpeed;
break;
case 1 :
Ball.xSpeed = -(Math.random(Ball.mySpeed))*Ball.mySpeed;
break;
default :
break;
}
var randomAction = random(2);
switch (randomAction) {
case 0 :
Ball.ySpeed = Math.random(Ball.mySpeed)*Ball.mySpeed;
break;
case 1 :
Ball.ySpeed = -(Math.random(Ball.mySpeed))*Ball.mySpeed;
break;
default :
break;
}
}