playMaker

Author Topic: change direction on touch  (Read 5234 times)

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • View Profile
    • Permaximum Betty
change direction on touch
« on: July 30, 2011, 06:07:34 PM »
Well i do want to know how to do this with playmaker.

Lets say i have a character that i want to move him left and right.
He is always moving up or down depending on where it is.
So i want to move him left or right when he does that.
I want to make a gui texture on my bottom on the screen for the left and right button.
When i press one of those it shall go left or right.
Its a touch screen so it must work with that and with the gui texture.

How can I do this with playmaker??

giyomu

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 108
    • View Profile
    • blog
Re: change direction on touch
« Reply #1 on: July 30, 2011, 07:01:24 PM »
Using the action guielementHitTest, and get the touch coordinate on screen ( there is an action for this ), so you can test if the touch hit he guitexture, form there either you flag a bool ( using global var can be good if you control your player in anther fsm, or send an event.

for a game i am doing i went with separate Fsm to detect the guiTexture input then flag between 2 global variable, on my another Fsm for player control ( in my case i just rotate left or right ) the player fsm check for the global variable and drive to 2 event ( one for left , other for right)

while turning right or left then i still check the corresponding boolean var so when the Fsm that handle GUIHIt set it to a false state, i can then stop my rotation, back to the previous Fsm that listen for both global and so on

that's one way to do , but it is not really complicate setup to do...

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • View Profile
    • Permaximum Betty
Re: change direction on touch
« Reply #2 on: July 30, 2011, 07:52:05 PM »
Well try that.
the character is controlled by an other script, but not FSM.
Sure i will try to change that to, but right now i want to check this out.

Can i send that action to fake a leftright.x=Input.GetAxis.....  ??
Or just transform.Translate(leftright);


EDIT.

Well i did put a GUI texture on the screen and can read it.
I can also move the character.
But thats my next problem.
How do I get the player position(vector3)?
How i can add/remove one unit from the x- axel that the character has?


« Last Edit: July 30, 2011, 08:39:34 PM by Damian »

giyomu

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 108
    • View Profile
    • blog
Re: change direction on touch
« Reply #3 on: July 30, 2011, 09:33:43 PM »
you can use GetPosition to find our current player position , eventually you want put those into global variable , that may be easier to set that between Fsm.

then you can use Set action for vector 3 or Set Fsm Vector3 if you need to access it from another Fsm, using a global var you will just need to hook up your global form whatever Fsm you want

If you are using regular script for your player , well I eventually encourage you to pass that into full dedicated Fsm for your player movement that will be easier to manage Fsm call etc...

I usually avoid having too much script <> fsm things, as I find it clutter more teh whole things that use all stuff within Fsm , or I just write custom action specific to the game.

otherwise you can communicate with script from Fsm , and form your script to Fsm , you just need to look up the playmaker functions in regular code.

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • View Profile
    • Permaximum Betty
Re: change direction on touch
« Reply #4 on: July 30, 2011, 09:53:02 PM »
Yes i did find some stuff that did work, but then all just breaked and now nothing seems to work.
But I will do a testlab and try do move around a block or something to see if i can figure all things out.
I guess i will learn soon, its so hard to change from coding to playmaker.
But i know it will be very useful in the end.

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • View Profile
    • Permaximum Betty
Re: change direction on touch
« Reply #5 on: July 31, 2011, 12:15:44 AM »
Well i did find it to get the player position, but when i try to move it the controller goes into a loop.
Maybe i doing it wrong, but i dont understand why cant move an other object in the state.
Do I need to do more fsm and put it on the player and not try to change it in the first state?
If so then its very weird way to do it.

giyomu

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 108
    • View Profile
    • blog
Re: change direction on touch
« Reply #6 on: July 31, 2011, 12:41:06 AM »
maybe some screen of your actual setup could help , it not easy to figure out what you do with your state .
but I do believe is just a little work on get a proper setup and you will get going, what you do in regular coding for gameplay is nothing more than set a serie of condition > action , that work the same with playmaker, the envelope is just different looking :)

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • View Profile
    • Permaximum Betty
Re: change direction on touch
« Reply #7 on: July 31, 2011, 10:43:33 AM »
Well i change it all the time, but I cant get it to work.
If the loop error is gone then nothing is happens.

Can some do an example on this?
It would be easier.
It only need to have a GUI texture and a sphere.
The only thing it need to do is when I click on the GUI texture it shall move the Sphere one unit.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3204
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: change direction on touch
« Reply #8 on: July 31, 2011, 12:21:12 PM »
You can use the Next Frame Event action to avoid an infinite loop when looping a few states every frame. Use the Next Frame Event to return to the Waiting For Input state (instead of FINISHED which can fire in the same frame and create an infinite loop).

Another way to set this up: An Idle state that waits for a touch, and a Move state that moves the sphere and returns to Idle when the touch ends. So instead of looping through multiple states in a frame, the FSM is always in one of 2 clearly defined states: Idle or Move.This is generally the preferred way to set up FSMs - think of the states you need and the conditions that would cause transitions between them.

Also consider splitting the input and movement FSMs into 2 FSMs. The Input FSM can send events to the Movement FSM. This has several advantages:
- You can test each FSM separately, using Alt-Click to send events that you haven't setup yet.
- Decoupling input allows other systems to control the movement FSM.

Hope this helps some...



Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • View Profile
    • Permaximum Betty
Re: change direction on touch
« Reply #9 on: July 31, 2011, 03:10:25 PM »
You can use the Next Frame Event action to avoid an infinite loop when looping a few states every frame. Use the Next Frame Event to return to the Waiting For Input state (instead of FINISHED which can fire in the same frame and create an infinite loop).

Another way to set this up: An Idle state that waits for a touch, and a Move state that moves the sphere and returns to Idle when the touch ends. So instead of looping through multiple states in a frame, the FSM is always in one of 2 clearly defined states: Idle or Move.This is generally the preferred way to set up FSMs - think of the states you need and the conditions that would cause transitions between them.

Also consider splitting the input and movement FSMs into 2 FSMs. The Input FSM can send events to the Movement FSM. This has several advantages:
- You can test each FSM separately, using Alt-Click to send events that you haven't setup yet.
- Decoupling input allows other systems to control the movement FSM.

Hope this helps some...




Well i will try with more FSM.
I guess i put one FSM on the object I want to move.
That way I could move it with different sources.

But its very little information on how to setup touchscreen stuff.
So more examples about this would be great.
I think it very common problem with touchscreen.
Unity3D have this problem also. its hard to get this simple stuff( if you know how it works)

But I will look into the lab and see if i can figure out how to call other FSM :-)


Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • View Profile
    • Permaximum Betty
Re: change direction on touch
« Reply #10 on: July 31, 2011, 03:49:24 PM »
Okey i did figure it out how to send and receive an event.
So it works in windows when I use alt-click.
But it dont work on the phone.
So i guess it dont read the touch. lol

giyomu

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 108
    • View Profile
    • blog
Re: change direction on touch
« Reply #11 on: July 31, 2011, 06:43:50 PM »
you can simulate touch with finger index 0 , using mouse left , i did that and it work using getmousedown or getmouseup, so this is handy to test without change code there , later on yeah you better to add a branching to define yoru platform and use either touch or mouse ( so you can test in editor without need use the remote all time )

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • View Profile
    • Permaximum Betty
Re: change direction on touch
« Reply #12 on: August 01, 2011, 03:53:46 PM »
Okey i did manage to get this to works tanks to your video.

But I cant find any global variable to set. I guess thats in playmaker 1.2.

This do work so that is no problem.
But its very hard coded and I wonder if there is a way to use Send FSM to the object instead and make the object respons with that?
I did try that before and it did send the command to the object and the object did move, but never stopped.
So i guess there need a check for it.
If there is a good way to do this on the object without to look in the gui for the action, then the FSM on the object could be used from more object without add a new FSM.

Also I did add touch on this system with the mouse, so it works both in windows and on the phone without any need to change the code. That´s awesome...

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • View Profile
    • Permaximum Betty
Re: change direction on touch
« Reply #13 on: August 01, 2011, 07:19:13 PM »
I have one more problem with this.
How can I check so the object dont leave the screen?
In code its just to check the screen size( or a value) and check the vector3 (or x/y) and if the value you want to add is bigger then this value you set it to max value it can be.
But i can see what action I shall use-

Its like this( not real code).

If Max value > (vector3 + new Value) then
  move object = (vector3 + new Value)
else
 move object = max value
End

giyomu

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 108
    • View Profile
    • blog
Re: change direction on touch
« Reply #14 on: August 01, 2011, 08:57:53 PM »
if your screen is fixe , you can use a combo of trigger to delimit your visible area, when you get a trigger event then you can lock your object to it current position.

trigger are very light I use a lot without suffer any perf down ( unless you sue mesh collider )