playMaker

Author Topic: How to detect if finger drag stops in correct spot or not?[SOLVED]  (Read 4933 times)

Slater

  • Full Member
  • ***
  • Posts: 123
So I have a working drag object FSM now. I actually have a solution to my problem, but it doesn't feel like the best one. I hope anyone have a better one to share.

In my FSM I have that I can click on an object (a shirt) and it gets selected. I can then click on a target object (a box) and the shirt will be animated/moved into the box. I also have it so that you can drag the shirt. This is where it gets tricky. I have made a rect in the area of the box and use rect contains. So when the finger stops, it moves over to rect contains state and checks if rect is true or false. If true it moves over to the animation/move state, all is good and if the finger stops outside of the rect the item moves back to its original position.

I am now making a few of these FSM in different scenes and I am not to happy about the rect thing. I think it would be much smarter if I could use the box as target or the box collider in some way.

If rect is the way to go, I would appreciate some help in how to calculate where it should be. As it is now I have to guess (since I cant see it) and then build to Ipad and try, and then back and change etc. It is pretty time consuming and boring.

Hope anyone has any idea. Cheers

P.S Website for our app is soon up so you can see what I have been working on :)
« Last Edit: October 26, 2012, 01:23:44 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to detect if finger drag stops in correct spot or not?
« Reply #1 on: October 23, 2012, 03:42:27 AM »
hi,

 I think you should simply user colliders/triggers and raycasting from the touch position.

for detecting that a shirt is indeed within a space in the world, you should also use triggers. but if it's simply a matter of detecting if a position on screen is over a gui component, it depends on the gui system you use?

 are you using Unity gui or nGui or ezgui or else?

bye,

 Jean

Slater

  • Full Member
  • ***
  • Posts: 123
Re: How to detect if finger drag stops in correct spot or not?
« Reply #2 on: October 23, 2012, 05:42:55 AM »
Well, its in 2D and I have made the shirt as a game object where it is placed in Z -5 (closer to the camera) and the target box is a game object in -4 (further away from the camera) with a front panel that is in Z -6 (close to the camera) so that it looks like the shirt goes into the box.

I use Unity GUI, but how is that related to this?

Collider/trigger, can this be used when it is not actually colliding since it is 2d and they are on different Z placement?


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to detect if finger drag stops in correct spot or not?
« Reply #3 on: October 24, 2012, 03:59:53 AM »
Hi,

 If you are using Unit gui, then you will need to use rects or mess with theunity gui api that is not covered by the current set of playmaker actions.

 It's easier with other gui solutions because most of them provide colliders images for the gui component, so it's very easy to detect if the touch is over a given component, the gui framework would actually tell you that by default most of the time.

bye,

 Jean

Slater

  • Full Member
  • ***
  • Posts: 123
Re: How to detect if finger drag stops in correct spot or not?
« Reply #4 on: October 25, 2012, 05:20:47 PM »
I actually got it working now with the 3d touch drag on camera script from the other thread. At the end of that script, when drag stops, I have it go into a new state where I use raycast. In there I raycast from the "Picked object" onto a layered target object. When "hit" it goes into a new state that does a send event over to my animations FSM and if I drop the item outside the target item, then it goes to finish through a bool test set to false over to another state that does a send event to my animations FSM telling the item to move back to its original spot.

Have a few smaller kinks to work out still but I think that it is all going to be great in the end.

Cheers!