I’m struggling trying to adapt Cinemachine (and other tools) to my project and right now I’m trying to get my movement vector to match the camera direction.
So I’m looking around with cinemachine and I want to apply force to player that rotates with the camera y axis.
If im pressing forward and have a vector of (0,0,1) and the camera is looking right, I want to rotate that vector so its now (1,0,0).
Make sense?
I’m sure its gonna need angleaxis, but everything I’ve tried is not working.
here’s the current code, if that helps:
void ApplyMovment()
{
Vector3 appliedMovement = new Vector3(movementHeading.x, 0, movementHeading.y);
if (isGrounded) appliedMovement *= Time.fixedDeltaTime * walkSpeed;
if (!isGrounded) appliedMovement *= Time.fixedDeltaTime * airSpeed;
appliedMovement = Quaternion.Euler(0, camera.rotation.y, 0) * appliedMovement;
//appliedMovement = Quaternion.AngleAxis(camera.rotation.y, Vector3.up) * appliedMovement;
rb.AddForce(appliedMovement);
}
EDIT:
This was the solution if anyone is wondering
void ApplyMovment()
{
Vector3 appliedMovement = new Vector3(movementHeading.x, 0, movementHeading.y);
if (isGrounded) appliedMovement *= Time.fixedDeltaTime * walkSpeed;
if (!isGrounded) appliedMovement *= Time.fixedDeltaTime * airSpeed;
appliedMovement = Quaternion.Euler(0, myCamera.eulerAngles.y, 0) * appliedMovement;
//appliedMovement = Quaternion.AngleAxis(camera.rotation.y, Vector3.up) * appliedMovement;
cameraRotation = myCamera.eulerAngles.y;
rb.AddForce(appliedMovement);
}