playMaker

Author Topic: Drop Area or Drop Target using Physics  (Read 1691 times)

Lubeaz

  • Playmaker Newbie
  • *
  • Posts: 4
Drop Area or Drop Target using Physics
« on: January 08, 2017, 06:05:47 PM »
Hi there!

I've being trying to achive a simple Drag and Drop system using just FSMs but there is a little thing I don't get to make it work (maybe I'm not using the right logic here)

Here it goes:  So, think about card games, where you have a hand full of cards, you pick one and you place it on a desired position on the board. I'm using Sprites with 2D Colliders and 2D Rigidbodies. The issue comes with the Triggers and Get/Set Positions. Once a card "enters the drop area", the position is set and won't change so, if you stop dragging, it will fly right to the drop area no matter what. I mean, that's what I was looking for, the mechanics work. BUT, what if I change my mind? What if I want to not place the sprite there but keep it instead in the original position?

I tried a script provided by other pluging and does exactly what I wanted: You keep pressed down the mouse and you will drag the sprite, if you cancel the drag, it will bounce nicely to its original position. If you place the sprite inside the drop target, it will be placed. End of the story. But, If you go over the drop target but not releasing the sprite, it won't save the position and force your sprite to stay there... I mean, if you cancel the drag even if you entered in the drop target/area, the draggable sprite won't fly there but to the original position like you cancelled the drag anywhere else on the screen.
Did I explain myself right? hehehe

Yeah, I want to make it work with Playmaker, but I just don't know how to set this "conditional drop area" using triggers or bool variables, or I don't get the logic behind it.

Any help/suggestions?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Drop Area or Drop Target using Physics
« Reply #1 on: January 09, 2017, 02:35:26 AM »
Hi,

You can actually use the new Unity UI for this, would that be a possibility instead of using 2d physics? if it's a card game, I don't think you need physics right?

 else, start a simple scene with simple square boxes and start clean. Come back to me if you still struggle, I'll come up with a sample.

 Bye,

 Jean

Lubeaz

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Drop Area or Drop Target using Physics
« Reply #2 on: January 10, 2017, 09:34:52 AM »
Ok, I've been two days working on this, didn't want to bother you guys and figure it out by myself :P

I followed your advise Jean and it works perfectly. I used simple images and layouts using the Unity UI System and added a basic drag and drop system using just event triggers components. Now I can drag and drop every card nicely.

The problem of the specific "drop areas for specific game objects" still remains though. I've been using bools, tags, code...I'm not able to make it work.


I got this Positions Holders where you can place only the correct cards
I tried a Compare Tag, Trigger2D event (this one doesn't work for me, not using physics) and some other crazy stuff I can remember now haha

Can you guys guide me a bit here? What would be the proper logic to follow using FSM?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Drop Area or Drop Target using Physics
« Reply #3 on: January 12, 2017, 01:30:54 AM »
Hi,

 you can be made aware of when a drag start yourself, when receiving "UGUI / ON BEGIN DRAG" simply broadcast a global event "DRAG STARTED" or something, each drop target can then check what's being dragged and can disable dropping if the user choose that target for dropping.

also, notice in the demo how the disable state of a drop target is handled, DEMO / UGUI / ON DROPPED is called before the system calls UGUI / ON END DRAG

so you have also a change during the dropping to act.

 Bye,

 Jean

Bye,

 Jean