playMaker

Author Topic: How to get negative y rotation?  (Read 1646 times)

Adam Z

  • Full Member
  • ***
  • Posts: 207
How to get negative y rotation?
« on: August 06, 2019, 08:45:35 PM »
I have a mesh that gets rotated along the Y using the mouse. If I select the object and move the mouse left, I get a negative Y number.   If I 'Get Rotation' of that object and store the Y in a float, I always get a positive number (0-360), even if the actual Y rotation of that object is negative. How can I actually get the correct world number?  Thanks!

What I'm trying to do: if the Y rotation is more than 45, trigger an event. If it's more than -45, trigger a different event.  So I was using a 'Float Compare', but since I can't use a negative number, I can never trigger the other event.
« Last Edit: August 06, 2019, 08:54:48 PM by Adam Z »

Athin

  • Full Member
  • ***
  • Posts: 163
Re: How to get negative y rotation?
« Reply #1 on: August 06, 2019, 11:12:47 PM »
Heya,

What I'd try is storing the original rotation before it moves and then store the end rotation after its done moving.  Take the first rotation value and subtract it from the new rotation value. 

That will give you the angle it moved at and can use that value how you'd like.

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: How to get negative y rotation?
« Reply #2 on: August 07, 2019, 12:31:16 AM »
If that last solution isn't good for you, here are two other possibilities:

1) Offset the starting rotation of the object. Eg; let's say right now you are starting at 0, so if you go down it's negative (so won't work). So start at 90 instead. Now you can go down 90 degrees before it reaches 0. This may work if the object doesn't need to do a full rotation.

2) Use colliders. I've done this for a first person controller. Basically have a trigger collider object on your item to rotate (maybe using an invisible rectangle object parented or etc), and other colliders to represent your limits. You don't block it physically like bumping in to it, but you use the triggers to make the action happen when it reaches 45 degrees and (for the limiting view angles in an FPS) to disable what ever would control the object to move any further.
I have attached a diagram I made for someone else who was asking how for ways to limit the swivel on a tank. In the diagram you see the barrel (which has a trigger collider) hits the upper invisible collider (representing how far up it's allowed to go), which sends the event to go to a state which takes away it's input to move up any further. It can only move down until it exits the upper limit collider.

Adam Z

  • Full Member
  • ***
  • Posts: 207
Re: How to get negative y rotation?
« Reply #3 on: August 07, 2019, 11:08:24 AM »
This is for my 3rd person character rotation. When I move the mouse to look left and right, I would like the mesh to play a step-in-place animation depending on the y-rotation of the camera.

As an example; say my camera and player mesh is at 0 on the y-axis.  When I move the mouse right the y-rotation of the camera increases. When it passes 45 I would like to play an animation of my mesh rotating right 45 degrees, then zeroing out the rotations to start the process again. Same for the left mouse movement. So I tried using a 'Float Compare' action to activate another state after 45 has been completed (I also tried an angle float action, cant remember what that was called). Anyways I can get it mostly working when the mouse moves right, but I can't get it to work when the mouse moves left because the y-axis rotation starts at 360 and goes down from there, not a negative number.

Adam Z

  • Full Member
  • ***
  • Posts: 207
Re: How to get negative y rotation?
« Reply #4 on: August 07, 2019, 11:10:01 AM »
1) Offset the starting rotation of the object. Eg; let's say right now you are starting at 0, so if you go down it's negative (so won't work). So start at 90 instead. Now you can go down 90 degrees before it reaches 0. This may work if the object doesn't need to do a full rotation.

This might work, I'll give it a try later tonight. Thanks.