playMaker

Author Topic: Joystick Direction to Rotation angle  (Read 3977 times)

Brighton

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Joystick Direction to Rotation angle
« on: June 17, 2013, 10:53:52 PM »
Hi,

So I'm trying to setup a camera relative vector that drives a float based on the difference of the direction the player is facing and where the left stick is pressing towards.

I can't use the Move Controllers because the Avatar is driving all the locomotion.

I want to take this float and pass it in as a float for the animator. So that if the player pressed in the opposite direction that the avatar would get the message to turn until the angle of the player & thumbstick lined up. So it's important that I am able to get a +/- 180 degree values from the player & thumbstick ables.

I have a Get Axis Vector, Transform Direction (avatar; 0,0,1), and a Vector3 Angle operation between the Axis Vector and Transform direction.

This kind of works, but it only returns positive results so the avatar only rotates clockwise. I tried multiplying the x-Axis to get a positive & negative rotation, but it doesn't work out when the thumbstick is pressed up & down.

I've run out of ideas on this.

tl;dr, I'm trying to get the camera relative delta between the angle of the thumbstick & the avatar direction as a float.

Is there an action I'm overlooking or a custom action that someone has written relating to this sort of thing?

Brighton

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Re: Joystick Direction to Rotation angle
« Reply #1 on: June 19, 2013, 06:42:17 PM »
I've made some progress on this. I've incorporated this solution http://answers.unity3d.com/questions/181867/is-there-way-to-find-a-negative-angle.html into a new operation on the Vector3 operator.

case Vector3Operation.NegativeAngle:
               var angle = Vector3.Angle(v1, v2);
                var cross = Vector3.Cross(v1, v2);
                if (cross.y < 0) angle = -angle;
               storeFloatResult.Value = angle;
               break;

And it appears to be returning the type of results I am looking for, however the direction might need to be flipped.

Success!:
« Last Edit: June 19, 2013, 07:41:48 PM by Brighton »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15072
  • Official Playmaker Support
    • View Profile
Re: Joystick Direction to Rotation angle
« Reply #2 on: June 19, 2013, 10:27:38 PM »
Hi,

 Very good, I am glad you can apply scripting into playmaker.

bye,

 Jean