Hello, I want to set brand new rotation angle (0,0,0) when my object rotation is 60,90 or 120. How can I do that?
Have you tried eulerAngles or localEulerAngles? like this:
object.transform.eulerAngles = Vector3.zero;
Doesn’t work how I want.
My script is, when I press A or D my wheels rotate by 30 degrees, but when I release my button I want them go back instantly to (0,0,0)
P.S. I did obvious -30 degress after release, but that gives me some bugs.
Can you show us your code?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WheelRotation : MonoBehaviour
{
private Transform transform;
void Start ()
{
transform = GetComponent();
}
void FixedUpdate ()
{
/Bug: Wheels rotate, but sometimes they rotate more times than needed/
// Debug.Log(transform.localEulerAngles.y);
if (Input.GetKeyDown(KeyCode.D))
{
transform.Rotate(0,30,0);
}
if (Input.GetKeyDown(KeyCode.A))
{
transform.Rotate(0, -30, 0);
}
if (Input.GetKeyUp(KeyCode.D))
{
transform.Rotate(0,-30,0);
}
if (Input.GetKeyUp(KeyCode.A))
{
transform.Rotate(0, 30, 0);
}
}
}
Use Code Tags:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WheelRotation : MonoBehaviour
{
private Transform transform;
void Start ()
{
transform = GetComponent<Transform>();
}
void FixedUpdate ()
{
/*Bug: Wheels rotate, but sometimes they rotate more times than needed*/
// Debug.Log(transform.localEulerAngles.y);
if (Input.GetKeyDown(KeyCode.D))
{
transform.Rotate(0,30,0);
}
if (Input.GetKeyDown(KeyCode.A))
{
transform.Rotate(0, -30, 0);
}
if (Input.GetKeyUp(KeyCode.D))
{
transform.Rotate(0,-30,0);
}
if (Input.GetKeyUp(KeyCode.A))
{
transform.Rotate(0, 30, 0);
}
}
}
Next… ‘transform’ is already a property of MonoBehaviour, so your transform field is unnecessary.
As for your problem… I’m not sure how setting the eulerAngles to Vector3.zero isn’t working. That would set the rotation to (0,0,0).
Is that really what you want? Why doesn’t it work? What does it do that doesn’t match your needs? How are you sticking it in this code?
One thing I need. When I release my key I want my object to give rotation coordiantes X: 0 Y: 0 Z: 0
And how is this not working?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WheelRotation : MonoBehaviour
{
void FixedUpdate ()
{
if (Input.GetKeyDown(KeyCode.D))
{
transform.Rotate(0,30,0);
}
else if(Input.GetKeyUp(KeyCode.D))
{
transform.eulerAngles = Vector3.zero;
}
if (Input.GetKeyDown(KeyCode.A))
{
transform.Rotate(0, -30, 0);
}
else if(Input.GetKeyUp(KeyCode.A))
{
transform.eulerAngles = Vector3.zero;
}
}
}
This will do SOMETHING, what is it doing, and how does that differ from what you expect?
In last frames I’m not clicking any buttons, wheels are bugged, but they should be in 0 0 0.
https://www.youtube.com/watch?v=19f9e9kkoX8
pls help
try this: transform.localRotation = Quaternion.identity;
Please note, this different syntax isn’t meant to confuse you
You could also write:
transform.localEulerAngles = Vector3.zero;
When your object is a child, the value you see in the inspector is the local (be it: position, rotation, or scale).
Duude, love you. Thank you very much
No problem Glad I could help. I had the advantage of seeing the hierarchy/knowing it was a child
heh.