我想倾斜玩家(靶子),如果他在任何方向移动(沿着X和Z轴),就像太空校车教程一样。但在同一时间,我想用操纵杆(绕Y轴)旋转他。我使用的代码如下:
void FixedUpdate()
{
float rotation = CrossPlatformInputManager.GetAxis("L_Horizontal");
float vertical_movement = CrossPlatformInputManager.GetAxis("L_Vertical");
Vector3 movement = new Vector3
(
CrossPlatformInputManager.GetAxis("R_Horizontal") * MovementForceMultiplier,
0.0f,
CrossPlatformInputManager.GetAxis("R_Vertical") * MovementForceMultiplier
);
if (DebugInfo) Debug.Log(player.velocity.magnitude);
Player.AddTorque(Vector3.up * rotation / TorqueDivisor);
Player.AddRelativeForce(0.0f, vertical_movement * VerticalForceMultiplier, 0.0f);
if (Player.velocity.magnitude < MaxSpeed)
Player.AddRelativeForce(movement);
Player.rotation = Quaternion.Euler(Player.velocity.z * TiltingMultiplier, Player.rotation.y, -Player.velocity.x * TiltingMultiplier);
}这是怎么回事?球员倾斜,但旋转(AddTorque)略有变化,仅从359级到围绕Y轴的1级(2级角度)。
我试着用AddTorque (和AddRelativeTorque )来让球员倾斜,但是它让他倾斜得太厉害了,而且很难在最大旋转上设定界限。我失败了。
当我评论"Player.rotation“的变化时,用AddTorque轮换播放器效果很好。
我需要倾斜和旋转,因为它必须模拟无人机飞行。你有什么想法吗,我能做些什么?
发布于 2015-10-01 22:14:30
将ship放入一个空的父GameObject中。使用父对象绕Y轴旋转,然后可以自由旋转船舶本身以使其倾斜或倾斜或任意旋转,而不会干扰或扰乱Y旋转。
https://stackoverflow.com/questions/32889769
复制相似问题