Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: nick_h82 on December 04, 2013, 12:30:22 AM

Title: Vector 2 from Z rotation and magnitude[SOLVED]
Post by: nick_h82 on December 04, 2013, 12:30:22 AM
I'm currently updating a project from 3d physics to the new Unity 2D system. Thanks Jean for the excellent new action set! I have all the basic interactions correct, however I can't quite wrap my head around the final stage.

I'd like to store a Vector2 derived from an angle along the z axis, along with a magnitude. I can get the rotation, and the magnitude would be a float variable, but I can't work out the translation of these to a vector2. I don't need to change the rotation and magnitude once set, instead I would blend between vector2s as the player moves around the scene (would be interested to discuss the best way of doing this too).

I'm pretty sure the Trigonometry and Vector2 action sets would contain everything I need, I just couldn't seem to apply the maths.

Edit, thought I'd expand on the blending aspect. Think of moving through a scene, with different regions of wind defined by direction, and magnitude. As the player moves in and out of these different triggers, the vector2s for each of these triggers would be added and removed from an overall value as sensed by the player.

Thanks very much,
Title: Re: Vector 2 from Z rotation and magnitude
Post by: jeanfabre on December 04, 2013, 04:51:38 AM

 I would not use vector2 here:

 a rotation in unity 2 is only a float, not a vector, it represent the z axis rotation of your sprite.

then you simply store the rotation and the magnitude as two separated float. I don't see the need to store both values into a vector2.

 If that's not suitable, can you explain more about your contexct and the use case for this vector2?


Title: Re: Vector 2 from Z rotation and magnitude
Post by: nick_h82 on December 04, 2013, 11:07:41 AM
Hi Jean,

Thanks for the reply. I'd like to move an object around based on the rotation and magnitude without actually rotating it, ie apply force in a direction that corresponds to the z rotation received. Think vectored thrust on a fixed angle craft. I had imagined that storing the values as a vector2, and feeding that variable into the vector slot in an add force 2d action would fulfill this.

Maybe I'm overthinking this- would be interested if there's a simpler solution using two floats as recommended, as it's much easier for me if I can modify those floats individually.

Title: Re: Vector 2 from Z rotation and magnitude
Post by: nick_h82 on December 05, 2013, 12:30:19 AM
Hi Jean,

I've tried out your suggestion with the two floats. It appears to both set rotation correctly (set rotation action), and apply the correct amount of force (apply force 2d). I've got both actions within the same state, both update per frame, and both act on the same rigid body which is set to fixed angle. I've got debugging helpers nested inside which show the rotation is occurring.

My problem is that even though the rigid body seems to rotate properly, the force always apples in the world X direction. There's no option to apply the force to 'self', are there any other ways of doing this?

Title: Re: Vector 2 from Z rotation and magnitude
Post by: nick_h82 on December 06, 2013, 11:23:58 PM
Couldn't get the force applied in the local space, so went back to highschool maths and got a solution working with the trig action set.

Took the local z angle, and magnitude I wanted. Then for the force to be applied in the x direction, got the cosine for the angle and multiplied by the magnitude, likewise with sine for the y. Applied both forces to the appropriate axis' in the rigid body, and it works a treat. The cool thing is that by the time the values are used, they're all just floats, I only really need to calculate the correct values once for each volume. Also avoids rotation which was my aim at the beginning.