playMaker

Author Topic: constrain position  (Read 15372 times)

gamedivision

  • Full Member
  • ***
  • Posts: 227
constrain position
« on: May 27, 2012, 10:45:14 AM »
how would i constrain the position of a thumbstick to the base

thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: constrain position
« Reply #1 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

 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


gamedivision

  • Full Member
  • ***
  • Posts: 227
Re: constrain position
« Reply #2 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

 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



gamedivision

  • Full Member
  • ***
  • Posts: 227
Re: constrain position
« Reply #3 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

 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



gamedivision

  • Full Member
  • ***
  • Posts: 227
Re: constrain position
« Reply #4 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.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: constrain position
« Reply #5 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

gamedivision

  • Full Member
  • ***
  • Posts: 227
Re: constrain position
« Reply #6 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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: constrain position
« Reply #7 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


and there is there a working package.

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

Bye,

 Jean

gamedivision

  • Full Member
  • ***
  • Posts: 227
Re: constrain position
« Reply #8 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

gamedivision

  • Full Member
  • ***
  • Posts: 227
Re: constrain position
« Reply #9 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

« Last Edit: May 28, 2012, 03:59:17 PM by gamedivision »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: constrain position
« Reply #10 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

gamedivision

  • Full Member
  • ***
  • Posts: 227
Re: constrain position
« Reply #11 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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: constrain position
« Reply #12 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/

 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

gamedivision

  • Full Member
  • ***
  • Posts: 227
Re: constrain position
« Reply #13 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/

 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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: constrain position
« Reply #14 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