playMaker

Author Topic: rotate during button pressed?[SOLVED]  (Read 5470 times)

TommyA

  • Playmaker Newbie
  • *
  • Posts: 26
rotate during button pressed?[SOLVED]
« on: September 02, 2012, 10:43:35 PM »
Hi,
I made a button which will rotate object 90degree of y-angle.
It's just simple action : OnClick --> set rotation
I want to change this like below.
If right button has been pressed(not tap or click), object will rotate to right direction slowly.
When release button, the rotate will stop.
I have NGUI and PlayMaker.
How can I do that?
Please anybody help me.
Thank you.
 
« Last Edit: September 10, 2012, 03:23:11 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: rotate during button pressed?
« Reply #1 on: September 05, 2012, 05:07:14 AM »
Hi Tommy,


 NGUI are simply gameObjects, so you can can already exercice yourself with a simple cube.

instructions:
1: create an Fsm on the GameObject you want to control
2: create two events: "RIGHT CLICK DOWN" and "RIGHT CLICK UP"
3: in the start state, add a "Get Mouse Button Down" action, set the "right" that sends the event "RIGHT CLICK DOWN". Add this event as a transition of that start state.
4: transit from "RIGHT CLICK DOWN" to another state called "turn"
5: in state "turn", add a "Get Mouse Button Up" action, set the "right" that sends the event "RIGHT CLICK UP"
6: transit from "RIGHT CLICK UP" back to the start state

and that's it, you'll get your behavior.

 if you have trouble getting this to work, let me know, and I'll send a working sample.

bye,

 Jean

Red

  • Hero Member
  • *****
  • Posts: 563
Re: rotate during button pressed?
« Reply #2 on: September 05, 2012, 07:44:51 AM »
And if you want to limit the rotation, you can extract the rotation as a vector3 (you can choose only the appropriate roation value) and then do a float test in the "mouse down" action where if the angle is at or over the value you want, just boost out... though, to prevent it from inching more each rotation, maybe make the vector3 and float compare before the rotation action (since the order that they're in in the state does matter.)

TommyA

  • Playmaker Newbie
  • *
  • Posts: 26
Re: rotate during button pressed?
« Reply #3 on: September 08, 2012, 04:14:49 AM »
Thank you for response.

The right button what I meant is not mouse button but GUI button.
First time, I just tried to use OnPress function of "UIEventsToPlaymakerFSM" script.
Instead of this, I used "Mouse Down" event and "Mouse Up" event.
It works very well!
I still don't know how to use OnPress function when release mouse or finger(incase of mobile).
But anyway, I made what I want.
Thank you. ;)

TommyA

  • Playmaker Newbie
  • *
  • Posts: 26
Re: rotate during button pressed?
« Reply #4 on: September 08, 2012, 05:18:45 AM »
There is a problem on mobile device.
I made GUI button with NGUI, and made Playmaker action on GUI button with "mouse down" and "mouse up".
It works well on PC.
But when I tried to launch on mobile (iPhone) device, the button has no response.
Is this different with "mouse down" and finger touch?
How can I do that on mobile device?

derkoi

  • Full Member
  • ***
  • Posts: 187
Re: rotate during button pressed?
« Reply #5 on: September 09, 2012, 03:22:22 PM »
I've attached my modified version of the UIEventsToPlaymakerFSM script.

Added to it is the OnSubmit and OnPress events.

Basically you need OnPress in both states, as when it is held down it stays in the state until released.

Add your rotate code to state 2.

See attached image.  ;)


TommyA

  • Playmaker Newbie
  • *
  • Posts: 26
Re: rotate during button pressed?
« Reply #6 on: September 10, 2012, 03:12:02 AM »
Thank you derkol.

Didn't know can be use just OnPress event on both states.
Pretty simple!

Thanks.  :D

derkoi

  • Full Member
  • ***
  • Posts: 187
Re: rotate during button pressed?[SOLVED]
« Reply #7 on: September 15, 2012, 08:36:24 AM »
You're welcome. Yeah it took me a little while to figure out the OnPress on both states too.  :)