我使用的是统一性5.1.2,如果这有所作为。将玩家对象围绕玩家对象移动一个光滑的圆圈
我有一个游戏对象的盾牌,我想围绕一个球员围绕一个圈子移动。我有一定程度的工作能力,盾牌对输入有很好的响应,但不会动画,因为它只是传送到新的位置,而不是在平滑的旋转中绕着一圈移动。游戏是2D自上而下,所以只能在x/y平面上工作。试图使用lerp和slerp,但没有得到任何喜悦
真的很感谢你的帮助,弄清楚这一个!
这是我到目前为止有:
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);
}
}
}
你想让'transform.position'平滑移动或'transform.rotation'吗? –
可能为你节省一点代码的东西是在空变换下父屏蔽,然后在播放器下面居中和父变换空变换。这样,你不需要弄清盾的旋转/位置,只需要旋转它的父母。 (只是提供替代您当前的方法。) – Serlite
@StevenMills transform.position。本质上,如果盾牌位于右下角,并且我将棍子直接移动到左上角,盾牌从左下角消失并立即出现在右上角,而不是平滑地绕着圆圈移动,直到到达新点。 –