- Home /
Movement object same distance as touch movement
I have an object that I want to move, and the main camera follows the object via a simple follow script. When a player slides their finger on the screen in the x direction, I want the object to move exactly that much in the x direction as well (in relation to the level, as the object is always in the center of the screen). No matter what I do, it seems my finger is moving around twice as far as the object. The complexity that I'm not understand comes from the fact that the camera is moving with the object.
This is the current code I have, where I try to use relative distances from their initial locations to move the object. Not working though...
void FixedUpdate ()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
objectStartPosition = objectTransform.position;
touchStartPosition = touch.position;
}
else
{
objectLocation.x = objectStartPosition.x + ( touch.position.x - touchStartPosition.x) / 100;
PlaceObject(objectLocation);
}
}
}
If anyone could help, I would be immensely thankful!
Thanks guys.
Your answer
Follow this Question
Related Questions
2D Camera (Android, Iphone) 1 Answer
Raycast Touch Android not working JS 2 Answers
Touch Controlled Camera Inertia 1 Answer
To route or not to route? 0 Answers
Why does my app function correctly in Unity Remote but not compiled as an app? 0 Answers