0
嗨,大家好我是这样写代码来围绕一个中心对象旋转一个对象的,但是我做了一些错误的事情,有人可以解释我是什么:)?围绕一个中心对象旋转对象
public void RotateCamera(GameObject _center)
{
Vector3 mousePos = camera.WorldToScreenPoint(Input.mousePosition);
Vector3 centerPos = camera.WorldToScreenPoint(_center.transform.position);
float angle = Vector3.Angle(centerPos,mousePos);
Camera.mainCamera.transform.Rotate(centerPos,angle);
}
更新后的代码仍然不工作:
void Update()
{
RotateCamera(_player);
}
public void RotateCamera(GameObject _center)
{
float speedMod = 10.0f;
Vector3 mousePos = camera.WorldToScreenPoint(Input.mousePosition);
Vector3 centerPos = _center.transform.position;
Camera.mainCamera.transform.LookAt(centerPos);
Camera.mainCamera.transform.RotateAround (centerPos,mousePos,20 * Time.deltaTime * speedMod);
}
是旋转的摄像头,但它需要看到鼠标之间的夹角位置和目标。所以如果我点击对象的右侧,它会向右旋转,或者如果我点击对象的左侧,它将向左旋转。这段代码不正确吗? – 2015-02-07 17:43:59
O wait我可以替换鼠标位置的rotateAround中的vector3吗? – 2015-02-07 17:45:39
我更新了上面的代码,但它仍然无法工作 – 2015-02-07 17:53:15