首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >同时更改Rigidbody.rotation和AddTorque()

同时更改Rigidbody.rotation和AddTorque()
EN

Stack Overflow用户
提问于 2015-10-01 22:11:45
回答 1查看 514关注 0票数 0

我想倾斜玩家(靶子),如果他在任何方向移动(沿着X和Z轴),就像太空校车教程一样。但在同一时间,我想用操纵杆(绕Y轴)旋转他。我使用的代码如下:

代码语言:javascript
复制
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轮换播放器效果很好。

我需要倾斜和旋转,因为它必须模拟无人机飞行。你有什么想法吗,我能做些什么?

EN

回答 1

Stack Overflow用户

发布于 2015-10-01 22:14:30

将ship放入一个空的父GameObject中。使用父对象绕Y轴旋转,然后可以自由旋转船舶本身以使其倾斜或倾斜或任意旋转,而不会干扰或扰乱Y旋转。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32889769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档