rotate value is correct but not implemented.

So for some reason, the value of the rotation is correct (180), but the reading on the game object is not.

This is at idle state (0 degree)

alt text

This is at reversed state (180 degree)

alt text

And this is the script that I have:

using UnityEngine;
using System.Collections;

public class NormalAttackScript : MonoBehaviour {
  void Start () {}
  void Update () {
    Debug.Log(transform.rotation.eulerAngles.y);
    Debug.Log(ParentScript.parentObject.transform.rotation.eulerAngles.y);
    if (transform.rotation.eulerAngles.y != ParentScript.parentObject.transform.rotation.eulerAngles.y) {
      transform.Rotate(0, -transform.rotation.eulerAngles.y, 0);
      transform.Rotate(0, ParentScript.parentObject.transform.rotation.eulerAngles.y, 0);
    }
  }
}

Any help is appreciated, thank you.

I feel like your missing a ‘-’ at the if-statement. Didn’t you mean:

if (transform.rotation.eulerAngles.y != -ParentScript.parentObject.transform.rotation.eulerAngles.y) {

Besides that, I don’t know what ParentScript is, but it looks like bad coding to call an object from a static class in this case. Can’t you store the parent object as a variable? Or by using transform.parent?

I guess your if condition is not getting a true value ever.

try changing it to like this.

if (Quaternion.Angle(transform.rotation.eulerAngles.y,ParentScript.parentObject.transform.rotation.eulerAngles.y)>0) {

or also,

if (Quaternion.Angle(transform.rotation.eulerAngles.y,ParentScript.parentObject.transform.rotation.eulerAngles.y)>=1) {

The ‘!=’ doesn’t work correctly with float values… it has small imprecision…so…

I found out that

child angle

transform.rotation.eulerAngles.y

is always updated to the parent angle

ParentScript.parentObject.transform.rotation.eulerAngles.y

And the value will always be the same unless offset angle is implemented.

I’ve fixed the problem by fixing my other scripts.
Thanks for the clues.