playMaker

Author Topic: Getting negative rotation and clamping?  (Read 3404 times)

Six66

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Getting negative rotation and clamping?
« on: August 16, 2016, 10:09:37 PM »
Hi, can someone help me get the rotation of an gameobject to return as a negative?

I'm trying to rotate the camera up and down on the x axis but it keep returning a higher number such as 359 once i go below 0.
Is there a way to get a negative number like how it shows it in the unity inspector under transform?

I want to clamp the camera at min of -45 and max at 45.

Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15205
  • Official Playmaker Support
    • View Profile
Re: Getting negative rotation and clamping?
« Reply #1 on: August 17, 2016, 04:12:19 AM »
Hi,

There is an action called "GetSignedAngletoTarget" on the Ecosystem, that should do.


 Bye,

 Jean

WarpZone

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Re: Getting negative rotation and clamping?
« Reply #2 on: October 10, 2016, 05:02:19 PM »
I just wanna clamp my camera's Y rotation to -45 and 60.

I looked in the FloatClamp script and I don't understand why it exhibits this behavior.  It just uses Mathf.Clamp.  Doesn't Mathf.Clamp handle negative numbers?

So I installed Ecosystem (which was relatively quick and painless, thanks for that,) and downloaded "GetSignedAngletoTarget," but now I have no idea how to use it.  I tried rotating my camera, then getting the X axis (Direction means Axis, right?) and storing it in a temp variable, then passing that to the FloatClamp action, but that always results in 0.

I have no idea how this script works or what it's supposed to do, or even how this is supposed to solve the OP's question.  Which is the same as my question: How do I clamp my camera's rotation?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15205
  • Official Playmaker Support
    • View Profile
Re: Getting negative rotation and clamping?
« Reply #3 on: October 11, 2016, 03:01:16 AM »
Hi,

 I confirm that floatClamp allows you to clamp on the negative side.

In order to master each of these actions, isolate them and toy around with them individually, then you will be able to extrapolate on how to combine them together.

In your case however, you don't need any custom actions, the secret is to create a proxy float that keeps track of your rotation, as opposed to try and control the transform as is. you can of course do this is many different ways, but this is by far the most simple and easy to understand process.



 Let me know if you have still problems with this.

Bye,

 Jean

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • View Profile
    • Homepage
Re: Getting negative rotation and clamping?
« Reply #4 on: March 22, 2017, 05:30:10 AM »
Hi,

 I confirm that floatClamp allows you to clamp on the negative side.

In order to master each of these actions, isolate them and toy around with them individually, then you will be able to extrapolate on how to combine them together.


Hi, Jean!

I have the same problem, I think.

I have a space ship. And when I land the ship, it check the angle of the ship. If it's 10, it will crash, or if it's -10, it will also crash. When I use Get Rotation, it doesn't get negative rotation. Only 0 - 360. In my case, I don't think I can use Float Clamp, because I'm not going to set a new rotation. I'm going to get the rotation and store it in a variable and then use float compare.

Any ideas?
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15205
  • Official Playmaker Support
    • View Profile
Re: Getting negative rotation and clamping?
« Reply #5 on: March 22, 2017, 07:11:16 AM »
Hi,

 then you need something like "get Signed Angle to target"



Let me know if that still doesn't work.

Bye,

 Jean

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • View Profile
    • Homepage
Re: Getting negative rotation and clamping?
« Reply #6 on: March 22, 2017, 01:57:51 PM »
Hi!
I downloaded this Action also, but I can't get it to work with this. I don't know how to use it. Which Game Object should I use as the Target?

But the good new is that I got it to work with your example above with some changes.

This is what I did:
-Get Axis
-Float Add
-Set Rotation
-Float Compare - Float 1 = Angle, Float 2 = 360
 If Angle is greater than 360, then it reset the Angle to 0

-Float Compare - Float 1 = Angle, Float 2 = -360
 If Angle is less than -360, then it reset the Angle to 0.

This works as I want. :-)
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15205
  • Official Playmaker Support
    • View Profile
Re: Getting negative rotation and clamping?
« Reply #7 on: March 22, 2017, 11:04:34 PM »
Hi,

 yes, that's one option too.

 The target is going to be the reference to get the signed angle, so what you want is an object pointing up from the floor and that's the target, you'll then get the signed angle between your ship and that up direction. The orientation of the both the target and the source have to match, if you z axis target is not pointing more or less in the same direction as your source, then you will get odd results.

 always try an action in an empty scene with simple cubes, until you figure it out.

Bye,

 Jean

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • View Profile
    • Homepage
Re: Getting negative rotation and clamping?
« Reply #8 on: March 22, 2017, 11:07:58 PM »
Ok! Thanks for the help. I will give it a try. :)
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no