When i rotate on object ‘‘obj’’ on Y AXIS,a >particle system< (in wich this code is attached to) will change its size,speed and duration.
It is working fine. You can test it right now. Put this code in a particle system and simple drag any other object on the ‘‘obj’’ variable,and then rotate the ‘‘obj’’.
The problem is:
I use THIS:
storeY = obj.transform.rotation.y;
Debug.Log(storeY);
to get the ‘‘obj’’ rotation and store it in the variable ‘‘storeY’’. it works,but it does not get the rotation in degrees. Looks like it creates a value between 1 and -1,and the rotation is a decimal between these two…
Like i said,it actually works,but i would like to get the rotation in degrees,so i could control it a little better. It’s very hard to manipulate dozens of decimals like 0,9213493104.
What am i doing wrong?
if you guys want,you can simply show a whole new code that does that.
Thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ManipularParticula : MonoBehaviour
{
private float speed ;
/
private float ParticleSize ;
private float size ;
public GameObject obj;
public float storeY;
void Update()
{
storeY = obj.transform.rotation.y;
Debug.Log(storeY);
speed += Time.deltaTime * storeY * 100;
size += Time.deltaTime *storeY * 150;
ParticleSize += Time.deltaTime *storeY * 150 ;
GetComponent<ParticleSystem>().startSize = ParticleSize;
GetComponent<ParticleSystem>().playbackSpeed = speed ;
GetComponent<ParticleSystem>().startLifetime = size;
}
Check the documentation and you’ll notice that ‘transform.rotation’ is a Quaternion:
The x,y,z,w (yes w) of the quat do not represent rotations around a given axis. And instead is a composite of 3 complex numbers and a scalar. Quats are a bit complicated, but they mathematically compute better than euler angles (which is the x,y,z axis you’re used to).
If you want the euler angles, use the ‘eulerAngles’ property:
Note, all quats can be converted to euler angles as well (transform.eulerAngles really is just a forward to transform.rotation.eulerAngles):
I will point out though that if this is 3d and you rotate your “obj” around more than one axis. Your eulerAngles are going to start getting weird on you. It’s just the inherent flaw in euler angles and why we generally use Quaternions instead. You don’t really ever have to care about the inner working of a Quaternion… but you do have to understand how they commute (order of operations), and how you think about them. For example… things don’t “have rotation”, they have “have rotation relative to something else”. What does “45 degrees” even mean? Really it’s “45 degrees from some initial orientation around some axis”, you need to start considering those other bits of information when thinking about them. So if you’re like “I want to clamp my object to 45 degrees.” ask yourself “45 degrees from what?”
Man,you helped me so much.
After i read the article you sent,i understood the diference between Quaternion and euler angles (didn’t understood everything,but yeah…)
And i fixed the problem with one single line of code lol
Changing THIS:
storeY = obj.transform.rotation.y;
to:
storeY = obj.transform.eulerAngles.y;
Everything working 100% now. When i ''Debug.Log(storeY) i get my rotation in degrees.
Thanks!!!