- Home /
Why is Quaternion.Eular only rotating in one direction? [Answered]
Oh hai! So I got this weird thing going on and what I'm trying to do is instantiate a particle system and use the Qauternion.Eular to rotate it smoothly back and forth in this part of my script:
if(flamePlayer)
{
if(addt)
{
t = Time.time + 4.0;
addt = false;
}
if(!addt && Time.time < t)
{
if(make)
{
flame = Instantiate(flameThrowerPrefab, spawn.transform.position, Quaternion.identity);
make = false;
}
flame.transform.localEulerAngles.y = transform.localEulerAngles.y;
flame.transform.localEulerAngles.x = -30;
flame.transform.rotation = Quaternion.Euler(-30,
Mathf.Sin(Time.realtimeSinceStartup * flameThrowerSpeed) * flameThrowerAngle,0);
}
if(!addt && Time.time > t)
{
Destroy(flame.gameObject);
addt = true;
atPlayer = false;
flamePlayer = false;
make = true;
move = true;
}
}
It will create the object and rotate it but...it will only rotate it in one direction, as if the object's Y rotation is always at 0. I need the object's Y rotation as same as mine.
I'm not what you are asking or trying to do here, but let me make a couple of observations. On line 15 and 16, you assign the localEulerAngles independently. The reference for eulerAngles warns against setting them independently and I'm sure that applies to localEulerAngles as well. If you want to set them, put all three values in a Vector3 and assign them all at once. Note line 15 (assigning the 'y' to itself) does nothing.
But the above issues are not relevant because you completely overwrite the rotation in line 17. This nulls the previous two lines. Line 17 also sets the rotation to an absolute rotation in world space which is unlikely what you want and the reason for the behavior you see. I need a better understand of your desired behavior before I could suggest a fix.
Okay so you read my question you get that it the flame faces only in one direction. Well I want the flame to face the direction my boss is facing and still be able to rotate. It's like when the boss is facing 180-ish degrees Y it looks fine but then he faces the opposite and it's behind him. I just want it to rotate and face the same direction as the boss...
One easy way to solve this problem would be to use an empty game object. The empty game object would faces your target ('boss'). The physical game object would be a child object of the empty game object. You would use your $$anonymous$$athf.Sin() code above, but you would assign it to 'transform.localRotation' not 'transform.rotation'.
Thanks! I just attached the flame object to it since it was already an empty and changed it to localRotation!