- Home /
player set to 0 on x-axis on play but in editor its set to -90 on x-axis
//New to coding. I'm stuck tried searching and what not... editor mode player set to -90 X-axis when in Play mode player set to 0 X-axis needs to be set to -90 X-axis in play mode.
[SerializeField] protected Vector3 m_from = new Vector3(0.0f, 0.0f, 0.0f);
[SerializeField] protected Vector3 m_to = new Vector3(0.0f, 0.0f, 0.0f);
[SerializeField] protected float m_frequency = 1.0F;
public float xSpeed = 0.0f;
public float ySpeed = 0.0f;
public float zSpeed = 0.0f;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
Quaternion from = Quaternion.Euler(this.m_from);
Quaternion to = Quaternion.Euler(this.m_to);
float lerp = 0.5F * (1.0F + Mathf.Sin(Mathf.PI * Time.realtimeSinceStartup * this.m_frequency));
this.transform.localRotation = Quaternion.Lerp(from, to, lerp);
transform.Rotate(
xSpeed * Time.deltaTime,
ySpeed * Time.deltaTime,
zSpeed * Time.deltaTime);
}
}
I'm assu$$anonymous$$g you just want to have the cannon barrel itself rotate by 90 degrees and not the whole thing? The update method you've posted forces the transform on which the script resides to rotate if m_to has a value. It's Serialized, so chances are the field for that script in the editor has a non-zero value. The fact you have the SerializedField m_to initialized to Vector3.zero doesn't mean much since it's quite possible you've assigned a value to that field in the editor.
Your answer
Follow this Question
Related Questions
transform.lookat axis switch during rotation 1 Answer
Getting each axis angle from a game object 0 Answers
Scripting in C# + Past 360 degrees 2 Answers
Rotating / Smooth look at direction for Player 1 Answer
Ragdoll toggle unity 2d 1 Answer