Quantcast
Viewing latest article 13
Browse Latest Browse All 51

How do I rotate a quaternion with euler angles?

I think my mind is just in a knot at the moment, since I feel this should be fairly easy. Right now I'm trying to rotate a quaternion by adding a few degrees to its y axis, so that its rotation is relative to different object. Maybe I should try a different approach though; I've got the player moving around and following a target direction based on joystick input, and I like how it rotates, but I want to make the movement relative to the camera, instead of based on worldspace. Here's the part I'm having trouble with: Vector3 targetDirection = new Vector3(horizontal, 0f, vertical); Quaternion targetRotation = Quaternion.LookRotation(targetDirection,Vector3.up); // this is where I'd like to rotate the quaternion. // targetRotation.eulerAngles.y += pRotation.eulerAngles.y; Quaternion newRotation = Quaternion.Lerp(rigidbody.rotation, targetRotation , turnSmoothing * Time.deltaTime); rigidbody.MoveRotation(newRotation); Edit: total brainfart. targetRotation.eulerAngles += new Vector3(0, parentRotation.eulerAngles.y, 0); Was the solution. I'll delete the post if this is redundant.

Viewing latest article 13
Browse Latest Browse All 51

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>