lundi 13 mars 2017

Creates ball clockwise or anti clockwise

enter image description here

Create balls

  1. if bar moving towards point A (clockwise),create ball on direction of B (anticlockwise).
  2. if bar moving towards point B (anticlockwise),create ball on direction of A (clockwise).

Here is my existing code

var randomRotation:Number;          

randomRotation = randomRange(_bar.rotation - randomRange(150,250),_bar.rotation + randomRange(150,250));
ball.rotation = randomRotation;
ball.x = stage.stageWidth * 0.5;
ball.y = stage.stageHeight * 0.5;

Bar movement

  1. move towards the shortest radius.

Here is my existing code

var angleDiff:Number = 180 - Math.abs(Math.abs(_bar.rotation - ball.rotation) - 180);
var angleDiffPlus:Number = 180-Math.abs(Math.abs((_bar.rotation+speed)-ball.rotation)-180);
var angleDiffMinus:Number = 180-Math.abs(Math.abs((_bar.rotation-speed)-ball.rotation)-180);

if (angleDiffPlus < angleDiff)
{
    dr = 1;
}
else if (angleDiffMinus < angleDiff)
{
    dr = -1;
}
else
{
    _bar.rotation = ball.rotation;
}

_bar.rotation +=  speed * dr;

So how can those problem can be solve.

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire