Quantcast
Channel: User mikyll98 - Stack Overflow
Viewing all articles
Browse latest Browse all 102

Answer by mikyll98 for Why isn't my Unity rotation check working?

$
0
0

I think the issue is in the last if condition: transform.rotation is aQuaternion,which is not directly comparable to the (I suppose) scalar value ofweapon.sweepingEdgeRange. Therefore, you should instead obtain theangle of rotation, around the z-axis.

For example, you could use transform.localEulerAngles,which is

The rotation as Euler angles in degrees relative to the parent transform's rotation.

// We use 'z' component for rotation around z axisfloat currentRotation = transform.localRotation.eulerAngles.z;if (currentRotation < 0){  currentRotation += 360;}if (currentRotation >= weapon.sweepingEdgeRange ||   currentRotation <= -weapon.sweepingEdgeRange){  Debug.Log("Too far!");  Destroy(gameObject);}

Viewing all articles
Browse latest Browse all 102

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>