我在做一个小行星克隆,激光需要射出飞船的前部,但是当我尝试用旋转矩阵旋转矢量时,它会乱七八糟地飞到屏幕上,我需要激光从飞船的前部拍摄,并让起始点与飞船保持360度。目前,它只以90度的角度直射,当船直面东面时。
以下是我目前所拥有的:
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));包括一些图片来更好地解释我的问题
左下角的原点
在90度直线射击
发布于 2016-03-09 10:57:35
您正在使用Vector2.Transform()错误。第一个参数是您想要与矩阵进行转换的“引用”向量。
在您的情况下,如果您希望函数返回激光起始位置的位置,则需要将Vector2(shipWidth / 2f,0)作为参数。
因此:
Vector2 laserStart = vPlayerPosition + Vector2.Transform(new Vector2(shipWidth / 2f, 0), Matrix.CreateRotationZ(angle));然后你就可以开始从这个位置提取你的激光了。
https://stackoverflow.com/questions/35813085
复制相似问题