【发布时间】:2021-08-02 01:58:02
【问题描述】:
我目前正在制作一个 Katamari/Billy Hatcher 游戏,玩家必须在其中滚动球体。当游戏开始时,玩家拥有正常的平台游戏控制,直到它接近球体,如果玩家按下“附加”按钮,玩家将成为球体的子项。我遇到的问题是每当发生这种情况时,玩家都会随着球体旋转。我尝试冻结玩家的刚体,使其停止旋转,但这只会停止球体的旋转。有什么方法可以在保持球体旋转的同时停止播放器的旋转?
图片: enter image description here 这是我的流程脚本:
Rigidbody hitRB;
public Vector3 offset = new Vector3(0, 0, 1);
public LayerMask pickupMask;
bool isAttached;
private void TouchingGum()
{
RaycastHit hit = new RaycastHit();
foreach (GameObject gumball in gumBalls)
{
if (Input.GetButtonDown("Attach") && Physics.Raycast(transform.position,transform.forward, out hit, attachRequireDistance, pickupMask))
{
isAttached = true;
Debug.Log(true);
}
else
{
isAttached = false;
}
}
if (isAttached)
{
hitRB = hit.collider.gameObject.GetComponent<Rigidbody>();
Vector3 heldOffset = transform.right * offset.x + transform.up * offset.y + transform.forward * offset.z;
hitRB.isKinematic = true;
hitRB.MovePosition(player.transform.position + heldOffset);
}
else if(!isAttached && !hitRB == null)
{
hitRB.isKinematic = false;
}
【问题讨论】:
-
我只是制作一个脚本让玩家跟随位置而不是孩子。这样玩家和 Sphere 就有了各自独立的旋转。
-
你也可以把它们都放在另一个空的游戏对象下
标签: c# visual-studio unity3d 3d rotation