- Home /
The question is answered, right answer was accepted
Float to angle coordinate?
I have a code that detects an angle and send out a float between 0 and 360 degrees called fAngle.
what I want to do is shoot a bullet with a rotation = to that float, so, if my player is looking up, the bullet would go up because fAngle = 90
Im new to programing so, if anyone has the answer scripted. It would be great. Because I have no idea how to use a quaternion,I have a code that detects an angle and send out a float between 0 and 360 degrees called fAngle.
what I want to do is shoot a bullet with a rotation = to that float, so, if my player is looking up, the bullet would go up because fAngle = 90
Im new to programing so, if anyone has the answer scripted. It would be great.
Answer by Llama_w_2Ls · Feb 13, 2021 at 08:55 AM
You don't need to know much about quaternions, and how they work because you can use the static methods that the Quaternion struct provides, for example, Quaternion.Euler
, which returns a rotation x on the x axis, y on the y axis, and z on the z axis, respectively.
Essentially, it's a way of converting a euler angle (90 degrees) into a quaternion (0, 1, 0 ,0 or smt). For example:
float yDegrees = 90f;
// Returns a rotation 90 degrees on the y
Bullet.transform.rotation = Quaternion.Euler(0, yDegrees, 0);
There are lots of other ways, that I would recommend instead, such as Quaternion.LookDirection(Vector3 direction)
, which returns a rotation, that makes an object face a direction. For example, if your gun fires a raycast, you can use the direction of the raycast to orientate your bullets to face the same direction as the gun.
Thanks! it worked by puting the float on the z axis (2d game)
Hi. If you found the correct answer, please mark this question as closed. Thank you.