我有一个真空吸尘器,它分为两部分,一个是嘴巴,另一个是吸尘器本身,管子连接到吸尘器。该管应该与嘴连接。两个零件都具有刚体和对撞机。我在管道上添加了一个铰链接头,并在其中通过了口刚体。当我制作键盘控件时,它们工作得很好。但是现在我必须对移动设备进行控制,而我无法使它们工作。现在,嘴巴正在按预期的方向移动,但我似乎无法根据需要移动清洁器。任何指导或解决方案都将非常有用!
我已经尝试过使口腔更干净,但是它不能正常工作。试图在没有僵尸的情况下伪造它,但也没有起作用。
移动控件代码
public void FixedUpdate()
{
var inputVector = new Vector3(CnInputManager.GetAxis("Horizontal"), CnInputManager.GetAxis("Vertical"));
Vector3 movementVector = Vector3.zero;
if (inputVector.sqrMagnitude > 15f)
{
movementVector = _mainCameraTransform.TransformDirection(inputVector);
movementVector.y = 0f;
rb.velocity = transform.forward * Speed * Time.deltaTime;
movementVector.Normalize();
_transform.forward =Vector3.Lerp(_transform.forward, movementVector, 3.5f*Time.deltaTime);
transform.rotation = Quaternion.Euler(new Vector3(0f, transform.eulerAngles.y, transform.eulerAngles.z));
}
if (inputVector == Vector3.zero)
{
rb.velocity = Vector3.zero;
vacuumCleaner.GetComponent<Rigidbody>().velocity = Vector3.zero;
}
}
PC控件代码
if (Input.GetKey(KeyCode.UpArrow))
{
rb.velocity = new Vector3(0f, 0f, -1f * Time.deltaTime * Speed);
//transform.Translate(Vector3.down * Speed * Time.deltaTime);
//cleaner.transform.Translate(Vector3.down * Speed * Time.deltaTime);
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, -90, -90f), RotAnimSpeed);
cleaner.transform.rotation = Quaternion.Lerp(cleaner.transform.rotation, Quaternion.Euler(0, -90, -90f), RotAnimSpeed);
}
else if (Input.GetKey(KeyCode.DownArrow))
{
rb.velocity = new Vector3(0f, 0f, 1f * Time.deltaTime * Speed);
//transform.Translate(Vector3.down * Speed * Time.deltaTime);
//cleaner.transform.Translate(Vector3.down * Speed * Time.deltaTime);
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, 90f, -90f), RotAnimSpeed);
cleaner.transform.rotation = Quaternion.Lerp(cleaner.transform.rotation, Quaternion.Euler(0, 90f, -90f), RotAnimSpeed);
}
else if (Input.GetKey(KeyCode.LeftArrow))
{
rb.velocity = new Vector3(1f * Time.deltaTime * Speed, 0f, 0f);
//transform.Translate(Vector3.down * Speed * Time.deltaTime);
//cleaner.transform.Translate(Vector3.down * Speed * Time.deltaTime);
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, 180f, -90f), RotAnimSpeed);
cleaner.transform.rotation = Quaternion.Lerp(cleaner.transform.rotation, Quaternion.Euler(0, 180f, -90f), RotAnimSpeed);
}
else if (Input.GetKey(KeyCode.RightArrow))
{
rb.velocity = new Vector3(-1f * Time.deltaTime * Speed, 0f, 0f);
//transform.Translate(Vector3.down * Speed * Time.deltaTime);
//cleaner.transform.Translate(Vector3.down * Speed * Time.deltaTime);
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, 0f, -90f), RotAnimSpeed);
cleaner.transform.rotation = Quaternion.Lerp(cleaner.transform.rotation, Quaternion.Euler(0, 0f, -90f), RotAnimSpeed);
}
if (!Input.anyKey)
{
rb.velocity = Vector3.zero;
cleaner.GetComponent<Rigidbody>().velocity = Vector3.zero;
}
我希望清洁器能够响应,但是它不会按预期旋转。它仅跟随嘴巴旋转,只有嘴巴旋转得很大。我也希望它也旋转一点。