I want the spawned gameobject to face the side of the camera point of view.
Vector3 DropPosition = Playercamera.transform.position + Playercamera.transform.forward;
Quaternion Droprotation = Playercamera.transform.localRotation;
DroppedItem = Instantiate(ItemsToDrop.AutomaticSidearm, DropPosition, Droprotation);
DroppedItem.transform.rotation = Quaternion.Euler(0,90,0);
The camera is a child, and the y axis uses a modulo operator, it also uses Quaternion.Euler()
to rotate. I’m not sure if this has a effect of the spawned item.
if (CursorLock == true)
{
Cursorfloat = 1;
}
else
{
Cursorfloat = 0;
}
float MouseX = Input.GetAxisRaw("Mouse X") * Sens * Time.deltaTime * Cursorfloat;
float MouseY = Input.GetAxisRaw("Mouse Y") * Sens * Time.deltaTime * Cursorfloat;
XRotation -= MouseY;
YRotation += MouseX;
// This line keeps the YRotation within -360 360.
YRotation = (YRotation + MouseX) % 360;
XRotation = Mathf.Clamp(XRotation, -90, 90);
transform.rotation = Quaternion.Euler(XRotation,YRotation,0);