Hey Guys,
i have a Problem to rotate a Object on his Y axes slowly over time. It should give the object a nice little spinning effect.
to my case:
i do have a little sword which is already rotatet 90 on the x axes. This is needed to make it flat, as i designed it horizontal. If i instantiated i have a little script on it which should spin the object on his Y axes (Tried this in the editor works nice) slowly over time.
here are some of my approches with the outcome:
//Mentioned numbers are in following order X, Y, Z
//Changes the EUler Axes from 90, 0, 0 to 90, 90, 90 and slowly changing the X value.
//transform.Rotate(0, speed * Time.deltaTime, 0);
//Remains the Euler Axes and slowly changing the z value
//transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + (speed * Time.deltaTime), transform.rotation.eulerAngles.z);
//Changes the EUler Axes from 90, 0, 0 to 90, 90, 90 and slowly changing the X value.
//transform.rotation *= Quaternion.Euler(0, speed * Time.deltaTime, 0);
//Changes the Euler Axes from 90, 0, 0 to 0, 0.2, 0 the 0.2 should be speed * Time.deltaTime
//transform.rotation = Quaternion.identity * Quaternion.Euler(0, speed * Time.deltaTime, 0);
//Remains the Euler Axes and slowly changing the z value
//transform.rotation = Quaternion.identity * Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + (speed * Time.deltaTime), transform.rotation.eulerAngles.z);
//Remains the Euler Axes and slowly changing the z value
//transform.rotation = Quaternion.Euler(90, transform.rotation.eulerAngles.y + (speed * Time.deltaTime), 0);
//Changes the EUler Axes from 90, 0, 0 to 90, 90, 90 and slowly changing the X value.
//transform.Rotate(0, speed * Time.deltaTime, 0, Space.Self);
All of this approaches doesent give the desired solution. And i absolut dont get the Problem.
So i have 2 Questions:
- How do i fix it?
- Where are my thought
problems or to make it simple a dummy
explantion for my specific problem?
i would really apprecatie if someone would take the time and explain it in a short breakdown.
Im aware that Quaternion an Rotation is a way bigger Topic, but i do hope that a quick explanition for my specific Problem would make mit a bit more Better and give me a better Understanding
Thank You!
Full Code of the Method if needed or if i made a mistake on the Translate:
void Update()
{
if (target == null)
{
Destroy(this.gameObject);
return;
}
Vector3 dir = target.position - transform.position;
float distanceThisFrame = speed * Time.deltaTime;
if (dir.magnitude <= distanceThisFrame)
{
HItTarget();
return;
}
transform.Translate(dir.normalized * distanceThisFrame, Space.World);
//Mentioned numbers are in following order X, Y, Z
//Changes the EUler Axes from 90, 0, 0 to 90, 90, 90 and slowly changing the X value.
//transform.Rotate(0, speed * Time.deltaTime, 0);
//Remains the Euler Axes and slowly changing the z value
//transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + (speed * Time.deltaTime), transform.rotation.eulerAngles.z);
//Changes the EUler Axes from 90, 0, 0 to 90, 90, 90 and slowly changing the X value.
//transform.rotation *= Quaternion.Euler(0, speed * Time.deltaTime, 0);
//Changes the Euler Axes from 90, 0, 0 to 0, 0.2, 0 the 0.2 should be speed * Time.deltaTime
//transform.rotation = Quaternion.identity * Quaternion.Euler(0, speed * Time.deltaTime, 0);
//Remains the Euler Axes and slowly changing the z value
//transform.rotation = Quaternion.identity * Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + (speed * Time.deltaTime), transform.rotation.eulerAngles.z);
//Remains the Euler Axes and slowly changing the z value
//transform.rotation = Quaternion.Euler(90, transform.rotation.eulerAngles.y + (speed * Time.deltaTime), 0);
//Changes the EUler Axes from 90, 0, 0 to 90, 90, 90 and slowly changing the X value.
//transform.Rotate(0, speed * Time.deltaTime, 0, Space.Self);
}