# Unity < symbol doesn't seem to be working...? (JavaScript)

This topic is 2432 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm using JavaScript and trying to do something pretty basic, but it seems to be screwing up somehow. I'm trying to make something that gradually rotates you from your current degrees to the desired degrees by (var TurnSpeed) per second.

The part that seems to be screwing up is one piece that's pretty much the same as another 3 pieces like it with slightly different formulas involved. I know it's this part due to other debugging I've done.

Basically, this specific piece is supposed to check if your (current degrees remaining to rotate) is less than your (degrees rotated every time this piece is ran) and if it's true, it prints some variables involved in the process, then switches your rotation directly from its current rotation to the desired rotation. This is just to prevent it from overshooting so you don't end up past the desired rotation (which would probably result in rotating in another circle and attempting to reach the desired rotation once again).

Here it is:

if ((toRotation.y - transform.eulerAngles.y) < (movement.TurnSpeed * Time.deltaTime)) { print("Snapped your y rotation from " + transform.eulerAngles.y + " to " + toRotation.y + " because your total remaining degrees to rotate (" + (toRotation.y - transform.eulerAngles.y) + ") was less than " + (movement.TurnSpeed * Time.deltaTime) + "."); transform.eulerAngles.y = toRotation.y; }

So, transform.eulerAngles.y is Unity's version of "current Y rotation" and toRotation.y is the desired Y rotation. As you can see, I debug " because your total remaining degrees to rotate (" + (degrees remaining) + ") was less than " + (how much you rotate)

In the debugger, I see stuff like " because your total remaining degrees to rotate (35.26) was less than 7.2"

They're the same formulas that are used in the if condition. How does that condition pass if it then goes on to print that 35 is less than 7.2? It doesn't make sense to me. Is there some way that the values could be changed between the condition passing and the print? This script is running in Unity's "FixedUpdate" function, so it should be going constantly.

After some further testing, it also seems to go off with another part of the code. They're all pretty much the same, though, based on whether you have to rotate positively or negatively and based on if toRotation.y is greater than or less than transform.eulerAngles.y (which is mostly just related to making sure it rotates smoothly and takes the fastest route possibly to get to the target rotation).

Any help on why this could be happening would be greatly appreciated,
Thanks!

##### Share on other sites
Could be type problem.

Print out the type of the variables using something like:alert(typeof toRotation.y);

##### Share on other sites
I actually went into my Unity sandbox project and tried this for myself.

 var targetRot = new Vector3(0,180f,0); var rotSpeed = 5.0f; function FixedUpdate () { if ((targetRot.y - transform.eulerAngles.y) < (rotSpeed * Time.deltaTime)) { Debug.Log("Snapped your y rotation from " + transform.eulerAngles.y + " to " + targetRot.y + " because your total remaining degrees to rotate (" + (targetRot.y - transform.eulerAngles.y) + ") was less than " + (rotSpeed * Time.deltaTime) + "."); transform.eulerAngles.y = targetRot.y; } else { transform.eulerAngles.y += Mathf.Sign(targetRot.y - transform.eulerAngles.y) * rotSpeed * Time.deltaTime; } } 

I slapped it on a cube and it seemed to work as expected... until I made rotSpeed negative. As soon as transform.eulerAngles.y went negative, Unity turned it into -359.3 or something around there. Remember that when you put a negative number into a component of transform.eulerAngles, it turns that into 360-(whatever the resulting value was). Eg. the first frame with rotSpeed negative actually resulted in transform.eurlerAngles.y becoming (360f - rotSpeed * Time.deltaTime). That may or may not help you with your problem.

• 10
• 17
• 9
• 13
• 41
• ### Similar Content

• I have already chosen my favorite from the concept artist which one do you like better 1 2 or 3?

Also still looking for a writer and a 3d artist message if you are interested!

• Hey There,
I am a developer and Im working on a blockchain based infinite runner type game. Right now, I am working on releasing the beta version with a couple other game developers, but would love to expand the team and have other talented and bright people contributing. The game portion of the project isnt very complicated, and wouldnt require anyone to pull thier hair out for it.
Thank you!

• I am trying to build a particle system for unity based on "Destiny particle architecture " released in Siggraph.
I encounter a problem in trying to understand how they iterated this:

Converted to spline function and the result is

i wanted to know how did they converted the function in the editor to represent the graph ??

• This is my first experiment use for create my original character little cute dragon chibi use zbrush and blender and use unity3d assest free for enviroment scene you have feedback?

• By Aryndon
Project Redemption is an semi-fantasy RPG with a linear story and an elaborate combat system.
We are building in Unity and are currently looking animators and artists.
What we are looking for
-Someone who is okay with split revenue/profits when finished
-Collaborate with others in the team. Do you have an idea/thought on what should be included? Tell us!