【发布时间】:2015-11-20 06:15:42
【问题描述】:
我已经做了很多搜索,但找不到解决这个问题的方法。
我想要的是控制一个游戏对象,它根据正确的模拟摇杆输入以固定距离围绕玩家对象旋转,与玩家运动无关。我还希望对象在玩家周围移动时朝外。
我已将模拟摇杆设置为播放器移动并正常工作,并设置并测试了右侧模拟摇杆,因此我知道输入正常。
我尝试过 transform.rotate、RotateAround、.position 和四元数等,但无法弄清楚或找到任何可能有帮助的东西。我对此很陌生,所以可能有一个简单的解决方案,我只是看不到它!
感谢您提供的任何帮助 :) 万分感谢
编辑 2:第二次尝试
所以到目前为止我已经得到了这个:
public class ShieldMovement : MonoBehaviour {
public Transform target; //player shield is attaced to
float distance = 0.8f; // distance from player so it doesn't clip
Vector3 direction = Vector3.up;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float angle = Mathf.Atan2 (Input.GetAxisRaw("rightH"), Input.GetAxisRaw("rightV"))* Mathf.Rad2Deg;
if(Input.GetAxis("rightH") != 0f || Input.GetAxis("rightV") != 0f)
{
direction = new Vector3(Input.GetAxis("rightH"),Input.GetAxis("rightV"), 0.0f ) ;
}
Ray ray = new Ray(target.position, direction);
transform.position = ray.GetPoint(distance);
if(Input.GetAxis("rightH") != 0f || Input.GetAxis("rightV") != 0f)
{
transform.rotation = Quaternion.AngleAxis(angle,Vector3.forward*-1);
}
}
}
我希望它是围绕玩家的盾牌平滑旋转到一个新的位置,而不是传送到那里。我已经尝试了一些 lerps 和一些 slerps,到目前为止,我所能做的就是从圆周上的一个点沿直线插入到新点。想不出一种方法让它围绕玩家旋转,就像你只是旋转摇杆一样。希望这是有道理的!
你有什么很棒的想法吗?
【问题讨论】:
-
您是否已经查看过 SmoothFollow 相机脚本?它使摄像机以一定的角度和距离跟随玩家旋转以面对他。您也可以调整跟随对象,并在移动摇杆时增加位置(x,0,z)。我现在无法对其进行测试,但查看脚本似乎是最终了解您需要做什么的好方法......
-
我会检查一下,谢谢 :) 如果有效,将发布 :)
-
检查了一下,有点明白它的来源,但我似乎无法理解。如果你想看看我到目前为止得到了什么,我已经发布了一个没有上面动画的部分解决方案(因为我无法让它工作):)
标签: c# unity3d rotation position