- Home /
Question by
PonderingPanda · Jan 11, 2021 at 02:14 PM ·
unity 2dtop down shooter
How use the rotation of a public transform as a quaternion
I am making a multiplayer topdown shooter, and when I was violently forcing my script to fit multiplayer I saw i needed to use PhotonNetwork.Instantiate, but that makes it so I need to use quaternion. I am spawning the bullets from a public transform, and i cant figure out how to convert a public transform rotation to quaternion, or any other way to do this with PotonNetwork.Instantiate .
void Fire()
{
PhotonNetwork.Instantiate(bullet.name, new Vector2(firePoint.transform.position.x,
firePoint.transform.position.y), Quaternion.identity, 0)
}
thanks in advance.
Comment
Answer by logicandchaos · Jan 12, 2021 at 10:56 PM
A transform's rotation value is already a quaternion. So, transform.rotation is a quaternion. But you can convert it to euler notation with .eulerAngles, you can convert euler to quaternion with the static Euler method of Quaternion. Here is an example of both:
//convert rotation to euler
Vector3 eulerRotation = transform.rotation.eulerAngles;
//convert back to quaternion
Quaternion quaternionRotation = Quaternion.Euler(eulerRotation);
//Create a new quaternion from euler rotation
Quaternion newRotation = Quaternion.Euler(new Vector3(17,39,5));