- Home /
How to drag a GameObject with touch but at a limited speed
How to drag a player with touch but at a limited speed like if you drag it it would only move at a certain speed instead of the speed of you finger? I've seen http://answers.unity3d.com/questions/621539/how-can-i-drag-the-object-with-touch-mobile.html but it only works with your finger's speed. Any ideas? Thanks
To Drag at a set speed, you can use Vector3.$$anonymous$$oveTowards(). So say you've identified the the position where the finger want the object, you can do:
transform.position = Vector3.$$anonymous$$oveTowards(transform.position, targetPosition, speed * Time.deltaTime);
Thanks, but I still don't get how do you drag an object. @robertbu
I would do this for a 2D game, don't know 100% if this would work for a 3D game.
targetPosition = Camera.main.ScreenToWorldPoint (new Vector3 (Input.GetTouch (0).position.x, Input.GetTouch (0).position.y, 0));
void FixedUpdate () {
this.transform.position = Vector3.$$anonymous$$oveTowards(transform.position, targetPosition, speed * Time.deltaTime);
}
Answer by AlwaysSunny · Nov 04, 2014 at 03:54 AM
The input should define a target for the dragged object to seek.
The dragged object should move towards the target over time.
I don't really get what you mean, can you explain it a bit more or give me an example?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
touch input certain screen part 1 Answer
How to touch specific objects? 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer