playMaker

Author Topic: Calculate Total Rotation(s) - SOLVED  (Read 3981 times)

gregacuna

  • Full Member
  • ***
  • Posts: 143
Calculate Total Rotation(s) - SOLVED
« on: November 25, 2016, 12:59:01 PM »
I've create a "wheel of fortune" type of spinner and everything is working well except I want to be able to make sure players can't cheat by spinning it only a few spaces. I've tried several ideas to calculate that the wheel has spun at least 360 degrees, but it is tricky since each revolution starts the degrees again.

Is there any way to calculate rotations with full rotations plus partials?

BTW there is an Get Advanced Rotation action on the Ecosystem, but it isn't working and when I open the script in Visual Studio I just see a 404 Error. I copied the code from Github, but that didn't work either.

Thanks in advance!
« Last Edit: March 24, 2017, 01:56:47 AM by gregacuna »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Calculate Total Rotation(s)
« Reply #1 on: December 02, 2016, 02:27:02 AM »
Hi,

 on ecosystem, just try again, sometimes connection fails.

 what you need is is to add every frame the delta rotation of the wheel, then you'll get the absolute rotation.

so every frame,

-- get the rotation,
-- deduce it from the last rotation,
-- add it to the total,
-- save the rotation as the last rotation,


on start spinning, save the current rotation as the last rotation, and you are good to go.

If you have trouble, I'll do a sample.


 Bye,

 Jean


gregacuna

  • Full Member
  • ***
  • Posts: 143
Re: Calculate Total Rotation(s)
« Reply #2 on: March 23, 2017, 01:14:40 AM »
Is there a special action for getting the "Delta Rotation"? I've tried this using the "Get Rotation" and using Z (which is the axis rotating), but that doesn't really work since it is showing the Z position and not amount rotating.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Calculate Total Rotation(s)
« Reply #3 on: March 23, 2017, 01:59:24 AM »
Hi,

 the delta rotation is the current rotation minus the last time your recorded the rotation

in the start state: get the transform rotation in "Last Rotation" variable

 in another state,
- get the transform rotation in "New Rotation" variable
- substract "New Rotation" with "Last Rotation", save the result in "Delta rotation"
- Set "Last Rotation" to be equal to "New Rotation"

Is that giving you trouble?

 bye,

 Jean

gregacuna

  • Full Member
  • ***
  • Posts: 143
Re: Calculate Total Rotation(s)
« Reply #4 on: March 23, 2017, 02:38:02 AM »
Hey Jean,

Thanks for responding. I had already tried what you suggested, but using "Get Rotation" I was having real trouble since when the rotation passes a full 359.9 the numbers are suddenly smaller so the end rotation is smaller than the start...which really makes it complicated. Am I missing something?

I'm in the middle of trying the Get Delta Angle action which seems like it might work by converting the result to an Absolute number and just switching start/end positions depending on which is larger so then the distance rotated is calculated each time.

Does that sound like a good solution?

Thanks again!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Calculate Total Rotation(s)
« Reply #5 on: March 23, 2017, 04:34:32 AM »
Hi,

 true, true... you need to account for this case, it will be easier than other solutions that requires more vector based operations.

Let me work on a sample for this.

 Bye,

 Jean


gregacuna

  • Full Member
  • ***
  • Posts: 143
Re: Calculate Total Rotation(s)
« Reply #6 on: March 23, 2017, 05:31:45 AM »
Hey Jean,

I seem to have it working using the Get Delta Angle action. It is a MUCH simpler solution. Since the angle is computed from 0 to 180 and then back down from 180 to 0 all you need is to Float compare the start to end position and subtract the smaller from the larger.

My only concern is what happens when you're at say 170 and then pass 180 back to 170...then it would calculate it as if there was no rotation when in fact it has moved 20 degrees.

I don't think this is a real issue since it is calculating it frame by frame and the steps would be small, but I'll have to do some play testing to make sure. Curious if you have an idea on how to deal with something like that.

Thanks again!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Calculate Total Rotation(s)
« Reply #7 on: March 24, 2017, 01:48:24 AM »
Hi,

 Actually, I forgot to inform you, I already did the sample, it's on the Ecosystem:

https://twitter.com/JeanAtPlayMaker/status/844841015009718273

Bye,

 Jean

gregacuna

  • Full Member
  • ***
  • Posts: 143
Re: Calculate Total Rotation(s)
« Reply #8 on: March 24, 2017, 01:55:38 AM »
Fantastic! Can hardly wait to try it out. Thanks Jean!