2016-03-05 114 views
0

我正在做一個小行星克隆,激光需要射出船的前方,但是當我嘗試使用旋轉矩陣旋轉矢量時,它會失靈,在屏幕上飛行,我需要激光從船的前方射擊,並將原點留在船上360度。目前它只能以90度的角度直射,當時該船面向東方。旋轉精靈上的Vector2

這裏是我的時刻:

lLasers.Add(new Laser(Vector2.Transform(new Vector2((vPlayerPosition.X + 35), (vPlayerPosition.Y)), Matrix.CreateRotationZ(angle)))); 

凡角

Vector2 direction = mouseLoc - vPlayerPosition; 
angle = (float)(Math.Atan2(direction.Y, direction.X)); 

包括一些圖片,以更好地解釋我的問題

Origin in Bottom Left Corner

Shooting Straight at 90 degrees

回答

0

您正在使用Vector2.Transform()錯誤。 第一個參數是你想用Matrix轉換的「參考」向量。如果你想讓函數返回激光起始位置的位置,你需要給Vector2(shipWidth/2f,0)作爲參數。

所以:

Vector2 laserStart = vPlayerPosition + Vector2.Transform(new Vector2(shipWidth/2f, 0), Matrix.CreateRotationZ(angle)); 

然後你就可以開始從這個位置繪製你的激光。