- Home /
drag object ios
hello, my script drag player is functioning perfectly but when I touch the screen the player to "teleport" to the point I pressed .. I would like to know how to move .. not teleport .. This very fast motion (teleports) .. how do I move the object? not teleport. here is the script :
var object : GameObject;
function Update () {
for (var touch : Touch in Input.touches){
var ray = Camera.main.ScreenPointToRay(touch.position);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100)) {
if(touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) {
var cameraTransform = Camera.main.transform.InverseTransformPoint(0, 0, 0);
object.transform.position = Camera.main.ScreenToWorldPoint(new Vector3 (touch.position.x, touch.position.y, cameraTransform.z - 0.5));
}
}
}
}
Answer by Adamcbrz · Apr 17, 2012 at 04:20 AM
Not to be rude but I think you would find similar questions already asked if you search. Here is a similar question that I think has a few different possible solutions for you.
http://answers.unity3d.com/questions/238579/moving-objects-to-point-of-touch-on-iphone.html
Answer by yusufulutas · Apr 18, 2012 at 06:42 PM
I think you look at Mathf.SmoothDamp. it is useful. http://unity3d.com/support/documentation/ScriptReference/Mathf.SmoothDamp.html
Your answer
Follow this Question
Related Questions
How to apply offset to touch position when dragging object 4 Answers
IOS Object Pooling 0 Answers
Rotate on drag for IOS? 1 Answer
Android Object Drag With Touch Problem 0 Answers
Make object follow mouse, while actually moving camera, instead of object 2 Answers