Playmaker Forum

PlayMaker Help & Tips => iOS Help => Topic started by: gamedivision on May 27, 2012, 10:45:14 AM

Title: constrain position
Post by: gamedivision on May 27, 2012, 10:45:14 AM
how would i constrain the position of a thumbstick to the base

thanks
Title: Re: constrain position
Post by: jeanfabre on May 28, 2012, 01:38:13 AM
Hi,

You would have two different behavior,

1: when the user is touching, the thumbstick need to move with the touch position within the allowed range. for this there is an example that you can adapt.

https://hutonggames.fogbugz.com/default.asp?W882 (https://hutonggames.fogbugz.com/default.asp?W882)

 effectively, instead of using the usual input to move it, you would use the touch position.

2: When the user releases the touch  ( or it was cancelled)

you would simply animate back the thumbstick back to its base using for example iTween.


Bye,

 Jean

Title: Re: constrain position
Post by: gamedivision on May 28, 2012, 05:49:58 AM
for the return position i used a setposition in the idle state,but there is a bug with touch object event,when you slide your finger off the thumbstick it doesn't trigger the touch ended,touch cancelled,so your stuck in the touched state.so therefore it cant jump to its set position in the idle state.

Hi,

You would have two different behavior,

1: when the user is touching, the thumbstick need to move with the touch position within the allowed range. for this there is an example that you can adapt.

https://hutonggames.fogbugz.com/default.asp?W882 (https://hutonggames.fogbugz.com/default.asp?W882)

 effectively, instead of using the usual input to move it, you would use the touch position.

2: When the user releases the touch  ( or it was cancelled)

you would simply animate back the thumbstick back to its base using for example iTween.


Bye,

 Jean


Title: Re: constrain position
Post by: gamedivision on May 28, 2012, 07:47:38 AM
so looking at this example you have
get axis     (this gets the horizontal movement and stores it in the translation variable) 
float multiply  (this reduces the translation variable by however many increments you  want)
translate       (another guess that this puts the variable into real world co-ordinates like an x value)
get position   (not sure what this does)
float compare (these i think compare the current position  with the limit position,if it reaches the limit position then fires off the limit state,which in turn stops the movement with the set position)
float compare

for an actual thumbstick
id need to compare the horizontal and vertical axis so i suppose i need to use the get axis vector and a get touch info as well as a screen to world point then a set position
this im completely guessing haha,but a pointer in the right direction would be very helpful indeed,i read that the touch info stores the delta position which is the movement of touch using a vector3 variable,so maybe i wouldnt need the get axis vector
ohh i dont know

Hi,

You would have two different behavior,

1: when the user is touching, the thumbstick need to move with the touch position within the allowed range. for this there is an example that you can adapt.

https://hutonggames.fogbugz.com/default.asp?W882 (https://hutonggames.fogbugz.com/default.asp?W882)

 effectively, instead of using the usual input to move it, you would use the touch position.

2: When the user releases the touch  ( or it was cancelled)

you would simply animate back the thumbstick back to its base using for example iTween.


Bye,

 Jean


Title: Re: constrain position
Post by: gamedivision on May 28, 2012, 09:12:21 AM
so just to get started ive come up with this,the only problem is,it doesnt work haha
if i remove the float compare and get position then you can drag your thumbstick around the screen but with no limits.so the problem i have is limiting this to the circumference of the base,what i tried to do was use the float compare from your example but once at the limit range it doesnt return back to the touched event using the finished transition.
so if anyone can offer some input we can try and finally get a working joystick for everyone to use.

thanks
ohh and please forgive my complete newbish attempt at making this joystick control,i have no experience at all and this was just a common sense approach,if you dont try theory.

Title: Re: constrain position
Post by: jeanfabre on May 28, 2012, 10:34:13 AM

id need to compare the horizontal and vertical axis

Hi,

 no no, both axis can be treated independently. I see no reason to compare them, this make no sense both from a user perspective ( he can move where every he wants withint he joystick bounds), and from a development perspective ( it's perfectly acceptable to isolate the x and y axis on the same joystick , which is actually how it's done in the joystick script, x and y are computed separatly).

 but really, (I mean, unless you want to do this for the fun, which is completely welcome of course,) Simply use the joystick prefab and get the x and y using "get property" action and retrieve the "position" and store it in a Fsm vector2 variable, and inject it anywhere else you want ( back to other controllers for example).

Also from your attempt, I don't see anything that jumps to my eyes, so it must be something very simple, like  a wrong redirection or a wrong action order or something. Are you able to constraint one axe only? so that you can perfectly replicate the game sample Fsm, then add the other axis, but start simple first.

Bye

 Jean
Title: Re: constrain position
Post by: gamedivision on May 28, 2012, 10:38:29 AM
so jean should i just buy the penelope controller from asset store and use that,if so would it be just as easy to add animations to the get property action


thanks very much
Title: Re: constrain position
Post by: jeanfabre on May 28, 2012, 11:01:54 AM
buy??! no no, it's freely available, the penelope is just icing on the cake, but still freely available.

Import the mobile standard assets version from Unity, drag the joystick prefab system you want and work with that, it's all available for you right now :)

I actually did an action that bridge the joystick so that you can control it from Playmaker:
http://hutonggames.com/playmakerforum/index.php?topic=1344.0 (http://hutonggames.com/playmakerforum/index.php?topic=1344.0)


and there is there a working package.

http://hutonggames.com/playmakerforum/index.php?topic=230.msg5664#msg5664 (http://hutonggames.com/playmakerforum/index.php?topic=230.msg5664#msg5664)

Bye,

 Jean
Title: Re: constrain position
Post by: gamedivision on May 28, 2012, 01:54:02 PM
i see what your saying,but this is a gui texture and you cant batch gui textures,now if you add a jump button fire button base of the joystick and the score which could have 6 or 7 digits.thats 11 draw calls just for the controls,whereas if you use geometry for the buttons and score you can then batch them together and it would only be 1 draw call,
unless you can batch gui elements
Title: Re: constrain position
Post by: gamedivision on May 28, 2012, 03:00:45 PM
is there an actual demo of how to do this anywhere
cheers
also could i just drop that script onto another 2d thumbstick add an fsm,and it'll do the same thing


id need to compare the horizontal and vertical axis

Hi,

 no no, both axis can be treated independently. I see no reason to compare them, this make no sense both from a user perspective ( he can move where every he wants withint he joystick bounds), and from a development perspective ( it's perfectly acceptable to isolate the x and y axis on the same joystick , which is actually how it's done in the joystick script, x and y are computed separatly).

 but really, (I mean, unless you want to do this for the fun, which is completely welcome of course,) Simply use the joystick prefab and get the x and y using "get property" action and retrieve the "position" and store it in a Fsm vector2 variable, and inject it anywhere else you want ( back to other controllers for example).

Also from your attempt, I don't see anything that jumps to my eyes, so it must be something very simple, like  a wrong redirection or a wrong action order or something. Are you able to constraint one axe only? so that you can perfectly replicate the game sample Fsm, then add the other axis, but start simple first.

Bye

 Jean

Title: Re: constrain position
Post by: jeanfabre on May 29, 2012, 02:12:06 AM
Hi,

 I see you want to cut down on the draw calls. well, It's "simply" then a matter of using another mean of displaying the joystick, you would need to modify the code of the joystick yes, so that it uses a plane yes.

I would strongly recommend you don't worry about that right now, I assume you are at the early stage of development, so get it up and working, these kind of optimisations will make you loose focus on the important bits ( that's at least my experience of it :) )

so get it working with few more draw calls, see how it performs when everything that should be there on screen really is and then address them places you know can be improved IF it turns out it needs optimisations. In short only optimize when all features are in, else you will likely have to redo the work. I don't mean to encourage you to build junk, being aware and of all these possible problems are important, but I tend to approach them by iterating first a working version and then once I am happy with the feature, think how I can improve that and tight it better with the rest etc etc.

bye,

 Jean
Title: Re: constrain position
Post by: gamedivision on May 29, 2012, 03:22:17 PM
thats really great and sound advise jeanfabre,thank you.i found actually that playmaker supports ngui using the get property,so i think ill probably invest in that,i came up with an issue when using the batching tools and that is when you batch all items together,it also batches the meshes,so any movement wouldnt work or even altering the alpha channel on the textures for the jump and fire button causes everything to change its alpha at the same time,so i would have to use a 3rd party plugin and work around the communication aspect,i think the reason i fell into the trap of trying to figure things out on the fly,i wanted to learn playmaker using my own game.

Hi,

 I see you want to cut down on the draw calls. well, It's "simply" then a matter of using another mean of displaying the joystick, you would need to modify the code of the joystick yes, so that it uses a plane yes.

I would strongly recommend you don't worry about that right now, I assume you are at the early stage of development, so get it up and working, these kind of optimisations will make you loose focus on the important bits ( that's at least my experience of it :) )

so get it working with few more draw calls, see how it performs when everything that should be there on screen really is and then address them places you know can be improved IF it turns out it needs optimisations. In short only optimize when all features are in, else you will likely have to redo the work. I don't mean to encourage you to build junk, being aware and of all these possible problems are important, but I tend to approach them by iterating first a working version and then once I am happy with the feature, think how I can improve that and tight it better with the rest etc etc.

bye,

 Jean
Title: Re: constrain position
Post by: jeanfabre on May 29, 2012, 04:22:41 PM
Hi,

 You should investigate third party plugins yes, like 2d toolkit, ezgui and sprite manager 2, etc etc, they really help you being very efficient for mobile dev ( with texture atlas, and minimum draw call). they do allow you to have moving meshed within 1 draw call, I did that and it worked very well ( after endless nights of finding the right approach of course... :) )
http://www.kakimediadesign.com/2011/05/applis-ipad-cfm/ (http://www.kakimediadesign.com/2011/05/applis-ipad-cfm/)

 The app on this video is using sprite manager 2 and ezgui. It would simply NEVER work without them framwork  ( or similar),  draw calls varies from 4 to 10 on this app, and there are A LOT of interaction ( user interaction and predefine scripted animation, everything you see there is scripted, not animated in a 3d software and then imported)! so I am not sure what technic you are using to batch and find yourself stuck on moving the mesh, but you should really investigate further.

Bye,

 Jean
Title: Re: constrain position
Post by: gamedivision on May 30, 2012, 01:25:59 PM
i got to say jean thats looks amazing very professional.

Hi,

 You should investigate third party plugins yes, like 2d toolkit, ezgui and sprite manager 2, etc etc, they really help you being very efficient for mobile dev ( with texture atlas, and minimum draw call). they do allow you to have moving meshed within 1 draw call, I did that and it worked very well ( after endless nights of finding the right approach of course... :) )
http://www.kakimediadesign.com/2011/05/applis-ipad-cfm/ (http://www.kakimediadesign.com/2011/05/applis-ipad-cfm/)

 The app on this video is using sprite manager 2 and ezgui. It would simply NEVER work without them framwork  ( or similar),  draw calls varies from 4 to 10 on this app, and there are A LOT of interaction ( user interaction and predefine scripted animation, everything you see there is scripted, not animated in a 3d software and then imported)! so I am not sure what technic you are using to batch and find yourself stuck on moving the mesh, but you should really investigate further.

Bye,

 Jean
Title: Re: constrain position
Post by: jeanfabre on May 30, 2012, 01:53:07 PM
thanks :)  I wish these apps where available on the appstore, they are trying to push for this, but the content would need to be edited... oh well it's good already that they let us leaked that video anyway.

The coming iteration of these app will use AutoPilot to make the most of TestFlight, so very excited about that! AutoPilot IS A MUST HAVE for any iOS dev, I don't need to open xCode anymore nor upload manually, and so far it does work very well. I am saying all this because I know you target iOS, so if you haven't checked testFlight and autoPilot, please do, I even created actions to use TestFlight SDK with playmaker.
 
 Bye,

 Jean
Title: Re: constrain position
Post by: gamedivision on June 01, 2012, 06:02:31 AM
hi jean could you elaborate some more on the get property for the joystick,so what i need to do is map the movement of the joystick to the movement of the character on screen,do i use get property then select the target object which is the joystick then the property would be transform and store that in a vector3 if i can



thanks
Title: Re: constrain position
Post by: jeanfabre on June 04, 2012, 06:52:23 AM
Hi,

 yes, exactly, you will need to access the property of the joystick component, be it the vector2 or the individual axis ( as float), then you will have your values inside playmaker variables, available to be injected to your character controller ( you got that part covered I think)

I would suggest that you first create a Fsm Object variable, set its type of "joystick", then use the "get property" action referencing this Fsm Object, it will work very well like that.

 Bye,

 Jean
Title: Re: constrain position
Post by: gamedivision on June 05, 2012, 02:34:45 PM
your dual joystick already takes and stores the vertical and horizontal values and stores them into a float,sorry to bore you with the constant questions,how would i take those values from the floats and move something around the screen

on the create a third person controller tutorial he uses a vector3,get axis vector,controller simple move.but on your dual sticks your using floats


also another thing i dont understand,if i add a get property to your dual joystick choose transform,which is what i thought would be the x,y,z.
when i go to choose store object ,none of my variables show.

plus i dont understand what an fsm object variable is,i see get and set fsm object



thank you
Title: Re: constrain position
Post by: jeanfabre on June 06, 2012, 03:12:53 AM
Hi,

 1: I think you are over thinking this. The package I provided is merely the start for you to understand how the joystick works. I have attached a working package showing how to control a cube movement and rotation.

 the basic building block for this is to use the action "Joystick Bridge" and then plug the vertical and horizontal value into other actions performing something with the transform of a gameObject or else.

so in that example, I bind the right pad values to transltate the cube and I bind the left pad values to rotate the cube.

you might get confused as to how to do that from the prefab itself. You can absolutly implement your control IN the prefab itself, but it's also perfectly acceptable to not use that ( remove them Fsm if you never going to use them) and do as I did, simply implementing joystick bridges where ever you need it.


2: No you don't want to get the transform of the joysticks, you only want to use the values passed with the joystick bridge, the rest is only internal and will not reflect in a convenient way what you are after.

If you want to put the joystick bridge values into a vector 2 or vector 3, you can compose very easily the component of them vectors and insert in them the joystick values, you then pass that composed vector to your controller.

3: Fsm Object are a very convenient way to access public variables of any components available in your project, this effectily remove the need to have to create a custom action for each of these cases where playmaker can simply not provide an action for each individual api and behavior available in Unity, that is simply not a realistic task.

so, concrete example:

you want to control the field of view of the camera but you haven't spotted that an action exists for it. no problem.

1: drag a "set property" action onto a state,
2: drag and drop the camera component itself onto the "target object" field. you'll notice that the ObjectType informational field will switch to "UnityEngine.Camera"
3: select the "fieldOfView" property available int he drop down list of the "Property" field. a Float select will be shown
4: set the field of view float value here.

a Fsm Object can be ANY behavior currently available in your project and will like ALL pubic variable that Playmaker can handle

so instead of using set property and dragging the component you want to control
1: create a Fsm Object in the variable tab.
2: select the Object type to Unityengine.Camera
3: drag and drop the camera gameObject in the "objectValue" field
4: In the state where you have your set property, reference that variable in the "target object" field and proceed as usual to set one it property.

Hope this make more sense now. I am pretty sure one of the video tutorial do cover this, but I haven't watched them all, so can't say for sure.

 Bye,

 Jean
Title: Re: constrain position
Post by: jeanfabre on June 06, 2012, 03:31:54 AM
Hi,

 I made a working example of this Fsm Object usage. So have a look at this for a real integration of that.

http://hutonggames.com/playmakerforum/index.php?topic=1701.0 (http://hutonggames.com/playmakerforum/index.php?topic=1701.0)

Bye,

 Jean
Title: Re: constrain position
Post by: gamedivision on June 07, 2012, 05:14:17 PM
Sorry I haven't replied,my dog was really sick,she had a massive operation,had a big tumour removed from her leg.but she's on the road to recovery ,soon as I get the chance to try this I will,I can't wait,and thanks for helping me out,I didn't realise the transform would do that on the object you need to move.
Title: Re: constrain position
Post by: gamedivision on July 20, 2012, 03:24:27 PM
in the demo scene you provided with the double joystick and the box,what actually controls the speed of the box,so say if i wanted the box to move quicker