Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash AS3:以旋转角度移动对象_Flash_Actionscript 3_Actionscript - Fatal编程技术网

Flash AS3:以旋转角度移动对象

Flash AS3:以旋转角度移动对象,flash,actionscript-3,actionscript,Flash,Actionscript 3,Actionscript,所以我现在有一个半工作的东西,我说它是半工作的,因为它似乎以某种方式将角度旋转到最接近的45度左右,下面是代码: public function drive(e:Event) { speedX =Math.sin(carObj.rotation*(Math.PI/180))*2; speedY = Math.cos(carObj.rotation*(Math.PI/180))*2*-1; carObj.x += speedX * speed; carObj.y

所以我现在有一个半工作的东西,我说它是半工作的,因为它似乎以某种方式将角度旋转到最接近的45度左右,下面是代码:

public function drive(e:Event)
{
    speedX =Math.sin(carObj.rotation*(Math.PI/180))*2;
    speedY = Math.cos(carObj.rotation*(Math.PI/180))*2*-1;
    carObj.x +=  speedX * speed;
    carObj.y +=  speedY * speed;
}
有没有人知道一种更好的方法来获得准确的旋转角度(至少可以看得见,这样眼睛就看不出区别)并以给定的速度向该方向平移物体。

无需解决:

var carAngle:Number = carObj.rotation * Math.PI / 180;
carObj.x = carObj.x + speed * Math.cos(carAngle);
carObj.y = carObj.y + speed * Math.sin(carAngle);

//撞击物体后旋转,然后以一定角度移动,脸部朝前

var speedX:Number = randomRange(-10,10); // function generating random numbers
var speedY:Number  = randomRange(-10,10);

carObj.x += speedX;
carObj.y += speedY;

function calculateAngle()
{
 var radians:Number = 180 / Math.PI;
 //Calculate rotation
 var walkdirection = - (Math.atan2(tempAlien_mc.oldX - tempAlien_mc.x, tempAlien_mc.oldY - tempAlien_mc.y))*radians;
 //Rotating Car
 tempAlien_mc.rotation = walkdirection;
}

function randomRange(minNum:Number, maxNum:Number):Number   
{  
  return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);  
}