playMaker

Author Topic: How to touch and drag a 3d object?[SOLVED]  (Read 22504 times)

Slater

  • Full Member
  • ***
  • Posts: 123
    • View Profile
How to touch and drag a 3d object?[SOLVED]
« on: September 10, 2012, 09:04:21 AM »
Hi,

This is a nut I've been unable to crack and I have read and searched and tried numerous things without any luck.

I am trying to drag an object in my scene. Its a 2d setup, so only need to drag it in xy not z. I have tried using Touch Object Event and get it to move, but whatever I try it either moves however it wants/weird or it moves to slow and "drops" and you need to grab the item again.

So how do I go about doing this? I just want to pick a specific object and be able to drag it across the screen following my finger at "full speed".

I have found a lot of similar questions about this, but not a simple understandable answer yet.
« Last Edit: October 24, 2012, 12:56:06 AM by jeanfabre »

Sjones

  • Full Member
  • ***
  • Posts: 201
    • View Profile
Re: How to touch and drag a 3d object?
« Reply #1 on: September 10, 2012, 09:13:01 AM »
the iOS youtube tutorials for playmaker should give you the best advice, utilising the different functions throughout the get touch info section.

if its too slow make sure normalise information is set, using a screen pick and a bool test to send onto the move event, with the normalised info there shouldnt be any issue.

once you got the object keep running the fsm to get (touch location) and set (object location) position until touch ended.

have every frame on too.

Slater

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: How to touch and drag a 3d object?
« Reply #2 on: September 10, 2012, 03:32:57 PM »
Unfortunately I have tried all of that, watched all the tutorials several times, but none of them shows dragging an object.

This should be a pretty common feature for anyone to want. The best would even be if there was an action for it. Say touch drag object where you set what object to drag on touch and in what vector.

Sjones

  • Full Member
  • ***
  • Posts: 201
    • View Profile
Re: How to touch and drag a 3d object?
« Reply #3 on: September 10, 2012, 04:10:56 PM »
as long as you have the object specified (can get that from a screen pick) the attached screenshot will work, I use it to move a created object from the previous fsm

Slater

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: How to touch and drag a 3d object?
« Reply #4 on: September 11, 2012, 07:23:21 AM »
Thanks for your answer. Its working much better with your suggestion, but I still have a few problems. One is that the object is still moving a little bit to slow. It "lags" behind. If I drag a bit to fast, I drop the object and then it resets to the center of the screen.

So in my first state I have Touch object event and touch began that transitions over to a new state with what you showed in the screenshot. Any suggestions on how to have the object move faster and also not to have it center on screen if it would be dropped (which hopefully it wont when speed is good).

If I increase the collider it gets harder for the item to get dropped. Was trying to increase the collider in state 2, but couldnt find a way to do that. Also not sure if that is a smart way to go about it, increasing the collider to pretty much the screen size as long as you touch it?

Thanks for your help!
« Last Edit: September 11, 2012, 07:27:51 AM by Slater »

Sjones

  • Full Member
  • ***
  • Posts: 201
    • View Profile
Re: How to touch and drag a 3d object?
« Reply #5 on: September 11, 2012, 04:17:55 PM »
this to me sounds like lag, is this a completely empty scene with just the cube and also are you on an actual device or emulating it? i dont know about the iOS emulation (if there is one) but the android is supposedly really slow, this could be your issue.

dont forget that mobile devices can be extremely slow compared to PC's especially the older gen ipads etc (I read that the original ipad starts lowing fps at aprox 25 draw calls) compared to the new devices that I am currently running 100 draw calls at 60 fps.

if u got profiler use that to see how the device is handeling, if not there was an fps action somewhere on the forums recently, add that as an action and convert it to text and display on screen, it will give a good indication to how its running.

as to your question about making it not jump, have a finish state that goes out and back to your wait for input, use a touch event ended to trigger this event, it should keep the x & y values to their last value, keeping it exactly where it was, if that still doesnt work, copy the values and have an in-between state that on untouch uses the position that was saved and make sure it is set to where it was, then send event and finish back to the start state again.



Slater

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: How to touch and drag a 3d object?
« Reply #6 on: September 12, 2012, 04:05:26 PM »
I actually don't know why it is a bit sluggish, I don't think its a performance issue though. However I managed to do "Set Property" on the Collider so as soon as I move the object, the collider gets bigger and now I can't slide off the collider. When I stop the touch and it goes back to "wait for touch" state, it makes the collider smaller/to original size again. The slugginess is not that much, that it is enervating, it actually works out pretty nice now.

So thank you for the help!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14237
  • Official Playmaker Support
    • View Profile
Re: How to touch and drag a 3d object?
« Reply #7 on: September 13, 2012, 04:46:56 AM »
Hi,

ok, I have created a working sample. It uses a custom action I am a while ago,

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

It's named after "mouse" but really it was built up from the ground to accept just a screen position, so that works with anything really.

If you have problems understanding how it's done, let me know,

bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14237
  • Official Playmaker Support
    • View Profile
Re: How to touch and drag a 3d object?
« Reply #8 on: October 03, 2012, 10:44:05 PM »
Hi,

 ok, after a request, I modified the logic I implemented in that package above to overcome a issue with it.

basically, it doesn't check the gameObject you touch. That is, you touch and drag and no matter what it will.

Now in many cases you actually want to have control over what you are dragging and certainly want to let the user drag what he has touched. The package attached to this post is a variation that takes into account this situation. The logic is moved into the camera to becomes generic to the scene.

 To improve raycasting efficiency, I only raycast on a layer I created called "drag". All objects that can potentially be dragged are in this layer. It doesn't no mean that they are enabled for dragging, for this, I use a tag called "drag enabled" that I set on the object I want to be currently enabled for dragging, You can always set the tag of an object using the action "set tag". This layering it not mandatory, you could simply ignore layers and raycast everything and simply check for the tag itself.

The down side of this technic is that only one drag at a time can happen. This is likely fine, but if you want multiple dragging, then this dragging would have to be hosted by each individual gameObject that can be dragged, this way they work independtly and multi touch dragging can therefore happen.

As always, questions and comments are welcome,

Bye,

 Jean

Slater

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: How to touch and drag a 3d object?
« Reply #9 on: October 23, 2012, 07:39:33 PM »
Ha! Jean, I just decided to try your thingy out instead of the one that I had worked with, since I had a problem that when a finger already was on the screen, the object that I touched acted weird.

Since my work is in 2d I changed the camera to orthograpic size. I also changed touch detection to "moved" instead of "began", since I want it less sensitive and the option with my underlying FSM that have the object get selected and outlined and I didnt want the object to move with to much sensitivity.

I also had to change the setting in the drag state to World and lock Z to -40 (my camera is on -50). After that it works great. Now I only need to work out the colliding with target object thingy instead of using rect.

Cheers.

Slater

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: How to touch and drag a 3d object?[SOLVED]
« Reply #10 on: November 07, 2012, 04:16:51 PM »
So I had an idea for our website that we are launching very soon to promote the app we are making. The idea is to have the first scene playable on the website, so that the users can see and try it out. The problem I have right now is that everything I have done so far has been for touch. So on all the places that I have touch object event, I have now added mouse pick event as well and it seems to be working well.

The only thing I haven't sorted out yet is this drag functionality that I placed on the camera. It only works for touch now. How would I go about doing the exact same thing, but for mouse? Can I add something into this FSM or is there another one I can use that works the same and activate that when I build for mouse input?

 

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14237
  • Official Playmaker Support
    • View Profile
Re: How to touch and drag a 3d object?[SOLVED]
« Reply #11 on: November 08, 2012, 03:57:41 AM »
Hi,

 It's quite simple, on the states you check for touch events, also check for mouse events as well and trigger the same events of processes.

bye,

 Jean

Slater

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: How to touch and drag a 3d object?[SOLVED]
« Reply #12 on: November 08, 2012, 06:27:43 AM »
I'm a bit confused of the name of the action I should use and how. I can't find one called Mouse events. I only find mouse pick and mouse pick event, but they don't look the same as touch event.

Slater

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: How to touch and drag a 3d object?[SOLVED]
« Reply #13 on: November 09, 2012, 06:21:33 PM »
Sorry for bumping but I can't figure this one out. As I understand it, I need to put in something in 3 states, but I don't understand what to put in them. "check if this gameObject is allowed to be dragged", doesn't need anything more as I understand it. "Detect drag", "check target" and "drag" are the once I need to put something in to detect mouse actions. But I can't figure it out. I hope anyone can help me out here since we are planning on releasing the website this weekend and it would be nice to have this feature in it.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14237
  • Official Playmaker Support
    • View Profile
Re: How to touch and drag a 3d object?[SOLVED]
« Reply #14 on: November 12, 2012, 06:08:10 AM »
Hi,

 You simply need to use "Get Mouse Button down" and "Get Mouse Button Up" as extra actions next to the "touch event" actions.

If you need a working sample, let me know.

bye,

 Jean