playMaker

Author Topic: Test the Rotation of object  (Read 1929 times)

James_BBS

  • Playmaker Newbie
  • *
  • Posts: 8
Test the Rotation of object
« on: April 23, 2014, 03:32:32 PM »
Hey,

So I'm trying to figure out how to test when the player has rotated by 360 degrees. I've tried various methods but none seem to work. The method I was trying was to get the initial rotation of the object and then getting the current rotation of the object (I only care about the Z axis), then subtracting the current from the initial to see how much it's moved but sadly this doesn't work.

Anyone know how to do this?

Thanks

James

Tibo

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Test the Rotation of object
« Reply #1 on: April 23, 2014, 05:58:59 PM »
I think the problem you are facing is that depending on which side the player rotates, you might end up with negative values (if player rotates to the right, you'll eventually end up at minus something).


I'm not too sure if that would work, but you could try to convert the z-values you get to their absolute (in Math --> Float Abs) and then add them. If the result is >= 360, your player did a full turn.

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Re: Test the Rotation of object
« Reply #2 on: April 23, 2014, 06:58:59 PM »
I think Tibo is onto something with the float abs value. I had some rotating platforms, and I was trying to send events based on their rotation. Even though they rotated at a uniform rate ("rotate" action set to X degrees per frame), I noticed in the inspector that their rotation values would start at -90° [even though they were actually starting at 0], work their way to 0, then up to 270°, then jump to -270°, work their way to 90°, etc. Keep in mind only the numerical value was displaying like this, the platform continued to rotate smoothly as though going from 0° to 360°.

There's definitely something weird with the way Unity handles rotation values. In the end, what worked for me was ditching the "rotate" action. I added a float variable, added the amount I needed every frame, and then set the platform to set its rotation to that variable's value every frame as well. Not sure if this works for what you need but hopefully it helps give you some ideas!

James_BBS

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Test the Rotation of object
« Reply #3 on: April 24, 2014, 04:46:02 AM »
Thanks for the advice guys, I'll try and have a play around in the directions that you guys suggest. It's a really tricky one to solve and is puzzling me a bit.