精靈座標我有一個表示子彈及其基本實現一個精靈如下:更新基於其方向
function Bullet(x, y, rotation) {
this.x = x;
this.y = y;
this.direction = rotation;
this.speed = 5;
}
Bullet.prototype.update = function() {
// Move the bullet forward
this.x = Math.sin(this.rotation) * this.speed;
this.x = Math.cos(this.rotation) * this.speed;
}
我想要做的,是在前進的子彈它面對的方向和相對於它的速度。但是,當撥打update()
方法this.x
和this.x
時是NaN
。
如果給出它的x
,y
和rotation
信息,使精靈朝向它所面對的方向移動的正確方法是什麼?
嘗試推行'VECTOR'類。它會使這件事更容易處理。 – Blender 2013-03-09 21:14:47