Playmaker Forum

PlayMaker Help & Tips => iOS Help => Topic started by: magarcan on November 27, 2012, 11:22:22 AM

Title: Joystick movement
Post by: magarcan on November 27, 2012, 11:22:22 AM
Sorry about the title isn't very descriptive but it's a bit difficult to explain what I'm going to talk about.

First of all, thank to @jeanfabre for their examples. I'm using his work as a starting point.

(http://i45.tinypic.com/5ufsl1.png)
My idea is calc the distance between point (0,0) and the current one of the joystick. Then make a FMS, where:
-By default my character is in idle state
-If 0<distance<0,5 make my character state is walk.
-If 0,5<distance<1 my character state is running.

The problem is that the furthest distances are in the points (-1,-1) and (1,1) because my joystick's limit movement is a square and it's 1,41 instead of 1. In that case (http://gripati.com/flash/third-person-chracter-controller/), for example, the limit movement is a circle.

Are there a simply way to modify the movement shape?

Cheers!!
Title: Re: Joystick movement
Post by: jeanfabre on November 28, 2012, 12:41:30 AM
Hi,

Good point actually. It would be quite simple to implement and there are several approach:

-- modifying the joystick script to also output the magnitude of the joystick position ( 0-1 regarless of the angle)
-- store the joystick values in a vector3 and check for its magnitude using "vector3 Operator"
-- implement this speed check based on the character velocity

I would recommand the second approach. Simply watch the character speed and adjust the animation based on that speed. You can use "get Velocity" action to get the speed, and simply trigger the running animation over the walking.

Does that make sense?

bye,

Jean
Title: Re: Joystick movement
Post by: magarcan on November 28, 2012, 06:24:52 AM
Hi!

That's what i was doing:
(http://www.picamatic.com/show/2012/11/28/02/15/8837591_349x591.png)

I use Float Clamp because if you are in (1,1) your speed is 1.4 instead of 1 that should be the maximum normalized speed.

Another way to make the same is modifying the script:
Code: [Select]
` // Get a value between -1 and 1 position.x = ( gui.pixelInset.x + guiTouchOffset.x - guiCenter.x ) / guiTouchOffset.x; position.y = ( gui.pixelInset.y + guiTouchOffset.y - guiCenter.y ) / guiTouchOffset.y; // Normalize code ;) var angle : float; angle = Mathf.Atan(position.y/position.x); position.x = Mathf.Cos(angle); position.y = Mathf.Sin(angle); // Adjust for dead zone`
Anyway, I still has not been able to make the joystick movement a circle...
Title: Re: Joystick movement
Post by: magarcan on November 29, 2012, 09:33:09 AM
A little update:

• I've enabled 2nd joystick and it's controlling view
• I've finished the FMS that controls the animations

The next step is try to fix the shape of the movement  :-\
I'm a little lost with this so if anybody has some idea about how to fix it, please tell me.

Cheers!
Title: Re: Joystick movement
Post by: jeanfabre on November 29, 2012, 10:58:58 AM
Hi,

I think I get it now, you want the joystick to be constraint within a circle, not within a square.

Is that right?

bye,

Jean
Title: Re: Joystick movement
Post by: magarcan on November 29, 2012, 11:00:23 AM
Hi,

I think I get it now, you want the joystick to be constraint within a circle, not within a square.

Is that right?

bye,

Jean

That's exactly what I want!!

:-[ sorry for my poor English.
Title: Re: Joystick movement
Post by: magarcan on November 29, 2012, 11:38:07 AM
Hi!

Where has gone kiriri's post??

This is exactly how i try to fix it  ;D

First I calc de angle:
(http://i49.tinypic.com/mvgbrs.gif)

After that, I calc the size of the segments:
(http://i48.tinypic.com/2m678dw.png)

Yo can take a look here:
Code: [Select]
` // Normalize code ;) var angle : float; angle = Mathf.Atan(position.y/position.x); position.x = Mathf.Cos(angle); position.y = Mathf.Sin(angle);`
The problem is that I don't know how to apply that to the GUI movement...

Cheers!
Title: Re: Joystick movement
Post by: kiriri on November 29, 2012, 11:40:41 AM
(sorry I just read your solution(the script at the top) and deleted my post just before you posted your answer... didn't want to put it off so I post it here again)
Quote
ok, I know my ideas are always over complicated, but this sounds pretty sinus-cosinus-tangents- ish to me :D
So I've done some tests on my calculator.
cos^-1(x)/90 defines the maximum value of the y axis, if a certain x point is set. (In a circle of r = 1)
Same goes for y.

But then again, it's probably easier to calculate the distance to the origin. (though I like sinus & co :D)
make sure the local length of all of your axis is 1 (like you marked in your image, if you move your controller thingy to the end of the axis, it should show something like 0/1/0 or 1/0/0 or the like).
Then instead of using any expensive distance calculation just normalize your position vector and set it as the local(self) position. That should work I think. Just remember that normalizing a vector kills the negative values. So before you normalize it you need to get both the x and y coords as floats and check if they're less than 0. If they are you could set the float to -1, if they are not you could set that float to 1. Then after normalizing the vector you can build a new vector from your new x,y, and for z nothing
Then you can simply multiply your newly built vector with the normalized position and voila, that should make it work... I think, haven't tried it though.
Title: Re: Joystick movement
Post by: kiriri on November 29, 2012, 12:46:05 PM
try this project (don't forget to add you own PlayMaker plugin to the project first).
Very very simple setup, no math, change radius by scaling down the parent of the joystick.
You use it by layering it on top of the rendered scene (you use 2 cameras at once).

This is kind of gui is just so much easier to handle that I completely gave up on GUIObjects in favor of this system.
Before screen pick - ing you need to make sure that the main camera is the GUI camera, but that's just about the only shortcoming :)

PS:
I didn't create a muse drag thing, so you need to look from the top onto the red thing, select it, and then use the green plane to move it around at runtime to see how it behaves.
Title: Re: Joystick movement
Post by: magarcan on November 30, 2012, 11:43:49 AM
Hi all!

I've been trying to understand Joystick script. Using settings by default, the range you can move it's defined by vectors guiBoundary.min.x and , guiBoundary.max.

With default values:
(http://i50.tinypic.com/33zcscp.png)

I've tried to detect when you are moving out of the range, calculating hypotenuse and trying to modify values. Code is almost working but only in half of the surface.