hi, i was trying to write an script which allow me to rotate my space ship when i rotated my gun(with mouse) for after it rotated for a known amount, before that i asked for a help in my script which cuz of that i started using “Quaternion.Euler” in my script however i had no idea what it does at that time and now with the problem that happened i have no idea where things went wrong
the ship rotate just about find the problem is the ship’s gun no longer follow the parent(ship) rotation and what is happened is now my gun rotate in global rotation not the local, so how can i fix that??? i know it was hard to explain so maybe you should test the script yourself
void Update(){
//gun rotation
GunRotationX += Input.GetAxis("MX") * (Time.fixedDeltaTime * GunRotationSpeed);
GunRotationX = Mathf.Clamp(GunRotationX, -RotationLimit, RotationLimit);
GunRotationY += Input.GetAxis("MY") * (Time.fixedDeltaTime * GunRotationSpeed);
GunRotationY = Mathf.Clamp(GunRotationY, -RotationLimit, RotationLimit);
Gun.transform.rotation = Quaternion.Euler(GunRotationX, GunRotationY, 0);
//---------------------------------------------------------------------------
// the ship rotation:
if (GunRotationY >= RotationLimit - 15) { RoSpY = RoSp; }
else if (GunRotationY <= -RotationLimit + 15) { RoSpY = -RoSp; }
else { RoSpY = 0; }
if (GunRotationX >= RotationLimit - 15) { RoSpX = RoSp; }
else if (GunRotationX <= -RotationLimit + 15) { RoSpX = -RoSp; }
else { RoSpX = 0; }
RoY += RoSpY;
RoX += RoSpX;
RoZ += RoSpZ;
transform.rotation = Quaternion.Euler(RoX, RoY, RoZ);
}