# playMaker

### Author Topic: Input.touches - dragging and sliding a gameobject in Y-axis [SOLVED]  (Read 2981 times)

#### arwengrim

• Playmaker Newbie
• Posts: 7
• Learning making games
##### Input.touches - dragging and sliding a gameobject in Y-axis [SOLVED]
« on: September 28, 2013, 05:40:45 PM »
Following jeanfabre's example on basic input.touches I've managed to detect dragging and do some things while we are in dragging state and are hitting a specific gameobject with a raycast. However I would like a little help with going a bit further with this:

To the left is a placeholder that I already am able to detect if dragging is occuring inside.
To the right is a little heartcube. What I would like help with is to move this heart in only Y-axis according to where I am dragging on the placeholder. Where bottom should be 0% of the height and the top 100%. Simply put the heart should be in the same Y-position as my finger is on the placeholder.
I want it to work almost like a volume control from 0 to 100.
« Last Edit: September 30, 2013, 02:43:11 AM by jeanfabre »
I'm learning to make games. Please bare with me

#### jeanfabre

• Administrator
• Hero Member
• Posts: 15467
• Official Playmaker Support
##### Re: Input.touches - dragging and sliding a gameobject in Y-axis
« Reply #1 on: September 30, 2013, 01:52:53 AM »
Hi,

for this you need the following:

-- a start and end dummy gameobject within your placeholder system to know where the touch is within that range. use the start/end go to find out the length of your placeholder and then the start/touch go to find out where you are in percent.

-- using that percent you found above, you can now move the heart within that range too: adding the percent using the start go as a reference.

Does that make sense? it's simply cross product math here, the key is to define the start and end point of your placeholder range,

bye,

Jean

#### arwengrim

• Playmaker Newbie
• Posts: 7
• Learning making games
##### Re: Input.touches - dragging and sliding a gameobject in Y-axis
« Reply #2 on: September 30, 2013, 02:40:24 AM »
Thanks jeanfabre!

Sometimes the solution is so obvious when you see somone else write it  . I will test this and mark the post as solved once done.
I'm learning to make games. Please bare with me

#### Polynaught

• Playmaker Newbie
• Posts: 3
##### Re: Input.touches - dragging and sliding a gameobject in Y-axis [SOLVED]
« Reply #3 on: May 01, 2014, 04:29:32 PM »
Hi there,
I am new to PlayMaker and made it through the basic tutorials and already made a simple FSM using the input.touches asset that registers swipes and moves a camera accordingly. Nothing fancy. Works.

Now I'd like to move the camera when the INPUT_TOUCHES_DRAGGING event occurs. But I got stuck.

First I created a FSM on the camera and added a Listener state that waits for the dragging to occur.
Once this happens the transition points to a DragCamera state.
This state has the following actions assigned to it:
Input Touches Get Dragging Info - stores the delta in a vector2
Vector2 to Vector3  - transforms the vector2 into a vector3 (Z is 0)
Get Vector3 XYZ - stores the X of the vector3 from before in a float
Float Multiply - multiplies the float from before by a speed float
Get Position - gets the current camera position and stores it in in a vector3
Vector3 Add XYZ - adds the (0, X, 0) vector to the current camera pos vector3
Set Position - sets the new camera position

The result is a never ending camera movement either to the left or the right once I drag. And I guess it has something to do with the second step - I probably cannot translate the delta vector into a world space vector this easily.

How can I do this?

#### Polynaught

• Playmaker Newbie
• Posts: 3
##### Re: Input.touches - dragging and sliding a gameobject in Y-axis [SOLVED]
« Reply #4 on: May 03, 2014, 02:41:51 PM »
Sorry for this "spam" but I'm not sure if I made my point clear last time. So the following is the script I'd like to translate into a PlayMaker FSM. It does what I want (as described above):

Code: [Select]
`using UnityEngine;public class GameplayCamera : MonoBehaviour{ private float moveSpeed; public float MoveSpeedMultiplier = 0.5f; public float MaxOffset = 40f; public float Damping = 6f; void OnEnable() { Gesture.onDraggingE += OnDragging; } void OnDisable() { Gesture.onDraggingE -= OnDragging; } // Update is called once per frame void Update () { //get the current position Vector3 currentPos = transform.position; //calculate the x position float dist = Time.deltaTime * moveSpeed; //modify the temporary position currentPos.x += dist; //clamp the temporary position to the specified range currentPos.x = Mathf.Clamp(currentPos.x, -MaxOffset, MaxOffset); //apply the temporary position to the camera transform.position = currentPos; //reduce all the speed moveSpeed *= (1 - Time.deltaTime * Damping); } //called when one finger drag are detected void OnDragging(DragInfo dragInfo) { //horizontal movement is correspondend to -delta moveSpeed = -dragInfo.delta.x * MoveSpeedMultiplier; }}`

#### jeanfabre

• Administrator
• Hero Member
• Posts: 15467
• Official Playmaker Support
##### Re: Input.touches - dragging and sliding a gameobject in Y-axis [SOLVED]
« Reply #5 on: May 14, 2014, 08:34:41 AM »
Hi,

I made a new package for Input.touches.

It features a new scene implementing this behavior you paste the code from.

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

If you have any questions, let me know.

Bye,

Jean

#### Polynaught

• Playmaker Newbie
• Posts: 3
##### Re: Input.touches - dragging and sliding a gameobject in Y-axis [SOLVED]
« Reply #6 on: May 14, 2014, 04:06:29 PM »
Hey jean,
thx for updating the package with these new examples. I didn't know that you do not necessarily need to use the Start event for a Playmaker FSM to work - cool, learned something new

#### jeanfabre

• Administrator
• Hero Member
• Posts: 15467
• Official Playmaker Support
##### Re: Input.touches - dragging and sliding a gameobject in Y-axis [SOLVED]
« Reply #7 on: May 15, 2014, 12:31:18 AM »
Hi,

yep. in many many cases, I set my start state as " " so that the state name appears empty, and so I know this state does nothing. I sue this technic also within the logic itself, somes states are empty, just because I need some idling times and at a glance I can know what logic was processed because it landed on that idling state.

Bye,

Jean