Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Brighton on June 18, 2013, 01:53:52 AM

Title: Joystick Direction to Rotation angle
Post by: Brighton on June 18, 2013, 01:53:52 AM
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?
Title: Re: Joystick Direction to Rotation angle
Post by: Brighton on June 19, 2013, 09: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!:
(http://i.imgur.com/VI0ZnFZ.png)
Title: Re: Joystick Direction to Rotation angle
Post by: jeanfabre on June 20, 2013, 01:27:38 AM
Hi,

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

bye,

 Jean