[英]How do I make a object rotate around the center of the screen towards the mouse in unity?
[英]How to rotate the center of the screen
旋转屏幕时,就像搅拌机一样,我想将屏幕旋转到屏幕中心的一个点。 但是,由于屏幕中心,是一个2d坐标,所以即使屏幕中心向量出来了,对应的点也没有出来。 即使有一个向量,相机在直线上拍摄,该点也无法准确知道,所以我不知道旋转屏幕的中心点zpos。
我不知道如何指定屏幕中心坐标的 z 轴,以便它像搅拌机一样穿过屏幕中心。 网格图块是否基于 z 轴?
void setRotInsideOtherWay(Vector3 ve3)
{
Debug.Log(CameraManager.S.LookPos);
//1 this way is not work
//2 Lookpos is tranform.foward
//mCamParent.transform.Rotate(ve3);
//mCamParent.transform.LookAt(CameraManager.S.LookPos);
//
Camera.main.transform.RotateAround(point , ve3,10f);
}
编辑图片错误抱歉
[SerializeField, Range(0.0f, 1.0f)]
float lerpRate;
float xRotation;
float yRotation;
float xMovement;
float yMovement;
UndoRedo undoRedo;
//CamVectorSaver camVectorSaver;
// RecordStarter recordStarter;
[Header("Set in inspector")]
public GameObject replyObj;
public static event MouseMoved MouseMoved;
private static void OnMouseMoved(float xmovement, float ymovement)
{
MouseMoved handler = MouseMoved;
if (handler != null) handler(xmovement, ymovement);
}
private void Rotate(float xMovement, float yMovement)
{
xRotation += xMovement;
yRotation += yMovement;
}
void Start()
{
undoRedo = ObjectManager.S.gameObject.GetComponent<UndoRedo>();
// recordStarter = replyObj.GetComponent<RecordStarter>();
//camVectorSaver = this.GetComponent<CamVectorSaver>();
MouseMoved += Rotate;
}
void LateUpdate()
{
if (!SubCamManager.S.checkInOut)
return;
if (SubCamManager.S.mouseClickMode == MouseClickMode.Drawline
&& SubCamManager.S.mouseClickMode == MouseClickMode.Lasootool)
return;
if (Input.GetMouseButton(1)||Input.GetMouseButton(0))
return;
//if (Input.GetMouseButtonDown(2) && recordStarter.booRecordOn)
//{
// // camVectorSaver.EnableScript(false);
// recordStarter.RecordTime();
//}
InvokeActionOnInput();
if (Input.GetMouseButton(2)||Input.GetButton("Horizontal")
|| Input.GetButton("Vertical") )
{
xRotation = Mathf.Lerp(xRotation, 0, lerpRate);
yRotation = Mathf.Lerp(yRotation, 0, lerpRate);
//Gimballock
//transform.eulerAngles += new Vector3(-yRotation, xRotation, 0);
Quaternion yRot = Quaternion.Euler(0f, xRotation, 0f);
Quaternion xRot = Quaternion.Euler(-yRotation, 0f, 0f);
transform.rotation = yRot * transform.rotation * xRot;
}
}
void OnDestroy()
{
MouseMoved += Rotate;
}
private void InvokeActionOnInput()
{
if (Input.GetMouseButton(2))
{
xMovement = Input.GetAxis("Mouse X");
yMovement = Input.GetAxis("Mouse Y");
OnMouseMoved(xMovement, yMovement);
}
//키보드 사용 하는 부분
if (Input.GetButton("Horizontal"))
{
xMovement = Input.GetAxis("Horizontal") * 0.7f;
OnMouseMoved(xMovement, 0);
}
if (Input.GetButton("Vertical"))
{
yMovement = Input.GetAxis("Vertical")*0.7f;
OnMouseMoved(0, yMovement);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.