kingBook

导航

停车小游戏

//lunRotation轮子的方向[-45,45]
//把车轮向量分解成两个分量:X轴方向的为推力(前进力),影响汽车的位移
//Y轴方向的为旋转力,影响汽车的角度
onward = speed * Math.cos(lunRotation*Math.PI/180);//汽车位移,x轴方向的分力
var yy:Number = speed * Math.sin(lunRotation*Math.PI/180);//y轴方向的分力
var myRotation:Number = Math.atan2(yy, length);//汽车要改变的角度(弧度值)
trace("lunRotation:"+lunRotation,"myRotation:",myRotation*180/Math.PI);
rotation += myRotation * 180 / Math.PI;//汽车转向
//汽车位移
_velocity.x = onward * Math.cos(rotation*Math.PI/180);
_velocity.y = onward * Math.sin(rotation*Math.PI/180);
x += _velocity.x;
y += _velocity.y;
if (handleFriction)
{
	speed *= friction;//摩擦力
}

posted on 2019-05-22 17:15  kingBook  阅读(115)  评论(0编辑  收藏  举报