Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: 4ppleseed on March 01, 2015, 02:01:12 PM

Title: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: 4ppleseed on March 01, 2015, 02:01:12 PM
Hi guys,
Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event?? It means you can press down on a 2d collider, slide your finger off and the collider is still down.

Surely it should be able to detect if the 2d Object is no longer being touched??

Is there a fix for this, while still using 2D colliders?

Thanks!
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: jeanfabre on March 01, 2015, 03:39:38 PM
Hi,

 you can know this by listening to the enter and exit events ( you are using the unity 2d package from the wiki right?), and when it exits, it's not touching basically.

 If you have experimented with this and isn't what you expect, can ou detail what you want to achieve?


 Bye,

 Jean
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: 4ppleseed on March 02, 2015, 05:58:50 AM
You mean the 2D proxy? I don't think I have that in my scene, maybe that's the way to go?
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: jeanfabre on March 02, 2015, 06:08:17 AM
Hi,

 2D is not supported by default, you will need to use the Package provided on the wiki to work with physics 2d and 2d colliders.

https://hutonggames.fogbugz.com/default.asp?W1150

 Bye,

 Jean
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: 4ppleseed on March 03, 2015, 04:37:30 PM
Hi,

 you can know this by listening to the enter and exit events ( you are using the unity 2d package from the wiki right?), and when it exits, it's not touching basically.

 If you have experimented with this and isn't what you expect, can ou detail what you want to achieve?


 Bye,

 Jean

Hi Jean, I tried but I can't get it to work.

I want a button that you can press down and when you let go it pops back up. So far no problems. What happens next is you press the button down, slide your finger away from the button and it stays down.

I've added a 2Dproxy to the game object and have selected the Collision 2D Exit event and tried the Collision 2D Exit Global event but I can't make it go back to the Button UP state when I slide my finger away from the button and move out of the collision touch space.

Where am I going wrong?

Thanks.
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: jeanfabre on March 04, 2015, 03:34:46 AM
Hi,

 that's a typical requirement from the User Experience logic, you won't get the up event if you have downed on a element then moved outside of it. it's the same with your OS, try to mouse down on a button, move away from the button and release, you won't fire any action.

 Bye,

 Jean
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: 4ppleseed on March 04, 2015, 06:38:09 AM
Hi Jean,
And if I don't want the usual logic? Touch GUI event has a 'Not Touching' event, that would trigger when it wasn't being touched any more.

Surely most virtual controls/UI need to know the player has moved off the controls??

Touch Object 2D Event having a 'Not Touching' event seems so logical to me.

Other people have raised this issue in the past:
http://hutonggames.com/playmakerforum/index.php?topic=9335.msg44537#msg44537 (http://hutonggames.com/playmakerforum/index.php?topic=9335.msg44537#msg44537)

Thanks.

Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: jeanfabre on March 05, 2015, 01:38:36 AM
Hi,

 unfortunatly, I am not sure there is a way unless you implement a raw set of scripts listening to raw inputs from Unity and make it up, raycasting the 3d world and firing the up event even if exited the element it was down on.

 even the new UI system and eventSystem engine doesn't fire the up event if you are not over the element you where down on.

Can you explain your use case? maybe there is a way ( I am sure there is actually), but I need more context as to what you want to achieve.

Also, you will find a lot of third party systems implementing their own input management, like ngui, input.touches, and I know for a fact that Input.touche do fire input events regardless of the context, it's completly agnostice to whats in the ui or 3d, it may be an option for you and it has support for PlayMaker on the wiki. However, I must warn you that it's raw, that is you'll have to raycast and find out manually what is underneath the mouse or touch.

https://hutonggames.fogbugz.com/default.asp?W961

 Bye,

 Jean
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: 4ppleseed on March 05, 2015, 06:36:08 AM
It's pretty simple. I have a Move Left button next to a Move Right button. It's a two player game so there is a pair of these buttons in each corner of the screen. It's a pretty frantic game so players will be holding down the Left Button, slide their finger over to the Right Button and the Left Button will remain down. It makes the gameplay confusing and not fun, as you never fully feel in control.


Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: 4ppleseed on March 05, 2015, 06:37:52 AM
Maybe I could fire a cancel event to Left Button when Right Button is touched?
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: jeanfabre on March 05, 2015, 06:53:18 AM
Hi,

 no react on down, not up, so implement everything on MOUSE DOWN system event.
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: 4ppleseed on March 06, 2015, 06:22:55 AM
I got this working last night but it's such a long winded way  :(

Touch Object 2D Event, Get Touch Info, Store X and Y to floats, compare to where the button is. If lesser/greater than tolerance, cancel touch event.

That for all four buttons! So each has it's own Finger ID etc... it's really messy and I fear won't work when the screen is scaled?

I can't believe there isn't a simpler way to detect if a 2d object that was pressed down, has been moved away from in Playmaker :o
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: jeanfabre on March 06, 2015, 06:51:48 AM
Hi,

 Dealing with individual finger id is mandatory, else it's unreliable, this is the way unity works, and actually logical, since you can have many simultaneous touches, you need to keep track of the right touch for a particular button.

I don't think there is a simple way even in scripts. If you find script that does what you need, let me know, I'll see how it's been made and work out a solution in PlayMaker if it turns out simple.

Bye,

 Jean
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: allornothing on March 06, 2015, 08:14:36 AM
not 100% sure how to set up in playmaker/unity, but I solved the same problem in another engine by spawning a small object at the touch position, and then monitoring the collision between the touch object and the button. Releasing touch destroys the object.

Should be simple enough to implement in playmaker, would that work here?
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: 4ppleseed on March 06, 2015, 09:24:24 AM
Hi,

 Dealing with individual finger id is mandatory, else it's unreliable, this is the way unity works, and actually logical, since you can have many simultaneous touches, you need to keep track of the right touch for a particular button.

I don't think there is a simple way even in scripts. If you find script that does what you need, let me know, I'll see how it's been made and work out a solution in PlayMaker if it turns out simple.

Bye,

 Jean

Thanks Jean. Would what I'm trying to do work if we still used 'Touch GUI' with the 'Not Touching' event? I never used it but it seemed like it was for this purpose.
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: 4ppleseed on March 06, 2015, 09:26:46 AM
not 100% sure how to set up in playmaker/unity, but I solved the same problem in another engine by spawning a small object at the touch position, and then monitoring the collision between the touch object and the button. Releasing touch destroys the object.

Should be simple enough to implement in playmaker, would that work here?

Thanks, I'm pretty desperate to make it work, so I'll give this a go! It sounds just as equally complex as my current solution - so it can't be any worse  ;D
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: PlaymakerNOOB on March 10, 2015, 08:05:45 PM
I had the same problem, but resolved it by looking at it a different way.

Touch Object 2D Event (Start)
Touch Began, Touch Moved, Touch Stationary all trigger "Touch Start"
Store the fingerID as an int

Then send an event to specified FSM. In my case it was a gameobject that managed all the inputs.  Then a finished event

Touch Object 2D Event (Stop)
Filtered by fingerID as int
Touch Ended, Touch Canceled all trigger "Touch Stopped"

Then send an event to specified FSM. In my case it was a gameobject that managed all the inputs.  Then a finished event

Back to start.
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: 4ppleseed on March 12, 2015, 04:51:30 PM
I had the same problem, but resolved it by looking at it a different way.

Touch Object 2D Event (Start)
Touch Began, Touch Moved, Touch Stationary all trigger "Touch Start"
Store the fingerID as an int

Then send an event to specified FSM. In my case it was a gameobject that managed all the inputs.  Then a finished event

Touch Object 2D Event (Stop)
Filtered by fingerID as int
Touch Ended, Touch Canceled all trigger "Touch Stopped"

Then send an event to specified FSM. In my case it was a gameobject that managed all the inputs.  Then a finished event

Back to start.

I tried this and the problem remains. If I press down the button and slide my finger off the button, it remains down.
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: PlaymakerNOOB on March 12, 2015, 09:24:13 PM
Yep, went back and looked... I am also using the Touch GUI Event.  As 4ppleseed mentions, quite odd that not touching is only available in the Touch GUI event.

Though, maybe its me, i cant seem to get Touch GUI events to work correctly in Unity 5.

Edit -- I did get Touch GUI to work, I just forgot I need to "Make it visible" by having its screen position set somewhere between 0-1.

I think AllorNothing's suggestion is probably the best, as you can easily scale the object under the players finger.  Though it would require creating an object for each touch.  That way you can drag a finger onto the button and have it trigger and stop when its slid off.

not 100% sure how to set up in playmaker/unity, but I solved the same problem in another engine by spawning a small object at the touch position, and then monitoring the collision between the touch object and the button. Releasing touch destroys the object.

Should be simple enough to implement in playmaker, would that work here?

Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: 4ppleseed on March 13, 2015, 08:44:05 PM
Yep. I'm thinking the spawning an object that tracks play finger when down is the only way to go. Hey ho, off to rewrite my whole project I go  ::)
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: 4ppleseed on March 14, 2015, 12:22:22 PM

I don't think there is a simple way even in scripts. If you find script that does what you need, let me know, I'll see how it's been made and work out a solution in PlayMaker if it turns out simple.


Hi Jean,
Today out of desperation, I re-installed Unity 4.5.5

I used the Touch GUI Event...

(http://i.imgur.com/ANPnyDf.png)

And it works perfectly in my game.

It seems the Touch GUI Event is more advanced than the Touch Object 2D Event when it comes to options. But of course it's now obsolete since 4.6+

Is there a way you can add the functions of Touch GUI to Touch 2d Object? Especially 'Not Touching'.

Otherwise I'll have to convert the whole of my game from Rigidbody/Collision 2d to 3d and continue in 4.5 :(

Thanks.
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: PlaymakerNOOB on March 14, 2015, 07:55:07 PM
Its not obsolete, Gui Texture still functions in Unity 5.
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: 4ppleseed on March 14, 2015, 08:13:10 PM
Its not obsolete, Gui Texture still functions in Unity 5.

http://docs.unity3d.com/Manual/class-GuiTexture.html (http://docs.unity3d.com/Manual/class-GuiTexture.html) it says they are legacy in the Unity manual. How do you create a GUI Texture in Unity 5? Which menu is it in?

Edit: Hmmm.. I'm reading if you add an empty game object you can still add it as a component? Is that true?  :D
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: PlaymakerNOOB on March 14, 2015, 09:05:22 PM
Its considered legacy and outdated, although still supported.

In Unity 4.6 & Unity 5, Yes, you can add it as a Component.

Though, it has higher draw calls vs the new UnityGUI.  Although really, its probably negligible unless you get crazy with the GuiTextures.
Title: Re: Why doesn't Touch Object 2D Event have 'Not Touching' like Touch GUI event??
Post by: 4ppleseed on March 17, 2015, 08:11:08 AM
Ta. This works in U5 and it'll have to do for now  8)