Hello,
I am working on a game in which the player character can walk on a “planet” like thing. Best reference is probably Mario Galaxy.
I am writing a camera controller for that however my Mouse input is not turning when the player is turning.
If I have vertical Input and the player is upright than i get vertical rotation. However if i have vertical Input and the player is turned sideways I get horizontal rotation.
I would like to rotate my input based on the players rotation.
Does anyone have any suggestions how to rotate a quaternion?
Or ideas how to do it differently?
Thank you very much for any suggestions or ideas.
void Input()
{
vertical = -Input_Manager.GetInput().right_XInput * camSpeedX;
horizontal = Input_Manager.GetInput().right_YInput * camSpeedY;
}
void Follow()
{
rotVertical += vertical * Time.deltaTime;
rotHorizontal += horizontal * Time.deltaTime;
Quaternion rotation = Quaternion.Euler(rotVertical, rotHorizontal, 0);
// an Idea I had to always get the right Input vector relative to the player however I didnt know what to do from there
Vector3 xpos = camTarget.transform.up * vertical;
Vector3 ypos = camTarget.transform.right * horizontal;
Vector3 pos = xpos - ypos;
this.transform.localPosition = Vector3.Lerp(this.transform.localPosition, camTarget.transform.localPosition - (rotation * offset), speedSmooth * Time.deltaTime);
this.transform.LookAt(lookAtTarget.transform, camTarget.transform.up);
/*Ideas that didnt work
* Quaternion rotation = Quaternion.Euler(rotVertical, rotHorizontal, 0);
* Vector3 rotateQuaternion = rotation * (camTarget.transform.forward);
* rotation = Quaternion.LookRotation(rotateQuaternion, camTarget.transform.up);
*
* transform.RotateAround(camTarget.transform.position, camTarget.transform.up, vertical * Time.deltaTime);
* transform.RotateAround(camTarget.transform.position, camTarget.transform.right, horizontal * Time.deltaTime);
*/
}