playMaker

Author Topic: Grab and move.  (Read 2798 times)

kinetiknz

  • Junior Playmaker
  • **
  • Posts: 85
Grab and move.
« on: September 25, 2011, 09:48:15 PM »
Hey I have been designing a simple 3d plan viewer, and I am trying to make an FSM that allows the user to 'grab' a plane and move it wherever the mouse goes, then drop it. Similar to using the hand tool in photoshop. I'm getting stuck at every turn though, anyone have an elegant way of doing it??
Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Grab and move.
« Reply #1 on: September 26, 2011, 03:39:02 AM »
hi,

 the first question to ask is if you want to move the object compare to the screen or to a specific plane ( for example the zx plane wich would drag your model on the "floor".

in term of implementation. cut the problem into smaller pieces.

 can you build a fsm that when you click on a gameObject, you can record the position?
 can you build a fsm that record the drag vector of the mouse from the point you clicked in realtime ( that is as you move?
 can you build a fsm that record the hit position of the mouse on a particular plane ( fictions or actual)?

 If you can do all that, you have everything to build a drag system.

I started a thread on this actually:

http://hutonggames.com/playmakerforum/index.php?topic=272.0

 I should spend some time next week to build a screencast of how it actually works ( maddox commented on this and he's right).

 Bye,

 Jean

kinetiknz

  • Junior Playmaker
  • **
  • Posts: 85
Re: Grab and move.
« Reply #2 on: September 26, 2011, 05:12:26 PM »
 can you build a fsm that when you click on a gameObject, you can record the position? YEP!
 can you build a fsm that record the drag vector of the mouse from the point you clicked in realtime ( that is as you move? - MAYBE
 can you build a fsm that record the hit position of the mouse on a particular plane ( fictions or actual)? -YEP!

My main problem is having a true understanding on the structure of FSM's designing the flow.
Thanks again, I'll look out for your cast, and have another go on my own today.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Grab and move.
« Reply #3 on: September 27, 2011, 12:33:07 AM »
Hi,

 I see. Then the following might help you more.

 you can split features by fsm. for example, have on fsm responsible for managing the drag ( mouse click -> record position every frame until mouse is up). Use this fsm to also trigger two global events: "MOUSE DRAG STARTED" and "MOUSE DRAG STOPPED" and pass in the event or record in a variable the gameObject targeted for the drag ( the gameObject under mouse).

have another fsm reading the mouse position and casting a ray on a plane to get a 3d position.

 have a third fsm reacting to "MOUSE DRAG STARTED" and "MOUSE DRAG STOPPED" that read gameObject to move and the 3d position from the second fsm and move the actual model you want to follow that position.

 That's one possible way to cut it down. As you get more acquainted, you can see otherways and shuffle things around based on your need. You might for example have some more complex need where the dragged gameObject would only move or snap to particular elements or state, if you have several fsm invovled, it will be easier for you to add complexity. One fsm is to avoid for anything complex ( or where several "features" are defined).

 Bye,

 Jean