Stop Transform Gesture from moving object without cancelling

Ask for help and post bugs.

Stop Transform Gesture from moving object without cancelling

Postby kaltemrix » Wed Jan 10, 2018 4:36 am

Hi,

Thanks for the help you have given me previously.
For an application i'm developing, i require objects to stop moving past the edge of the screen when they touch the edge of the screen.
I have triggers set up in my application to test for what side of the screen i'm hitting (Top, Bottom, Left, Right), the part im curious about is the best way to go about implementing the stopping.
I first tried Cancelling the Gesture, but the issue with this is it requires the person to touch the screen again to keep moving.
I Secondly tried adding some code to the Transformer class to stop it moving in a specific direction when the trigger fires, however i can't seem to get this to work, and (being somewhat inexperienced) i suspect i'm doing it bad/all wrong.

Is there any chance i could get you insight on a possible solution?
Thanks again!
kaltemrix
 
Posts: 16
Joined: Wed Aug 02, 2017 3:16 am

Re: Stop Transform Gesture from moving object without cancel

Postby ireth86 » Wed Jan 10, 2018 7:19 pm

Hi @kaltemrix,
if you want the user to be able to keep doing the transform gesture, I think the second option is the best one for you.
After the trigger, you could try to not apply the translation to that gameobject (using a "isTriggered" bool into the object script could be enough): in the Transformer script (line #321, if you have the latest version) you can check if the gameobject has been triggered, and simply return without applying the translation.
ireth86
 
Posts: 13
Joined: Wed Sep 28, 2016 5:55 pm

Re: Stop Transform Gesture from moving object without cancel

Postby kaltemrix » Thu Jan 11, 2018 1:03 am

Hi @ireth86

Thank you for the reply. I've done some testing using the method you have provided. The the issue i'm having is determining the direction the object is moving when being transformed.
Currently i'm doing a comparison using 'gesture.DeltaPosition.y > targetPosition.y' to check if the object is moving up. I'm doing similar comparisons for the other 3 directions but only right is doing anything.
Are there other variables i should be using to do the correct comparison?

Thanks
kaltemrix
 
Posts: 16
Joined: Wed Aug 02, 2017 3:16 am

Re: Stop Transform Gesture from moving object without cancel

Postby ireth86 » Thu Jan 11, 2018 11:35 am

gesture.DeltaPosition returns the difference between the old (previous frame) and the new (actual frame) positions, so you could use it to check if the gameobject is going up/down/right/left simply by doing
Code: Select all
if ((gesture.DeltaPosition.x > 0) || (gesture.DeltaPosition.x < 0)) {
   // it means i'm moving left or right, so targetPosition will be some new Vector3(0, y, z)
   ...
 }

and so on.
In addition, you could eventually also check the position of the object in screen space, but if the values of gesture.DeltaPosition are "reliable" enought it should not be necessary.
Last edited by ireth86 on Thu Jan 18, 2018 1:04 pm, edited 1 time in total.
ireth86
 
Posts: 13
Joined: Wed Sep 28, 2016 5:55 pm

Re: Stop Transform Gesture from moving object without cancel

Postby kaltemrix » Tue Jan 16, 2018 8:18 am

Hey.

Cheers for that. Finally been able to get around to implementing this fix and its been working well so far.
kaltemrix
 
Posts: 16
Joined: Wed Aug 02, 2017 3:16 am


Return to Help and Bugs

Who is online

Users browsing this forum: No registered users and 3 guests