- Home /
Change input direction to camera's forward
This is basic vector math but somehow I'm still stuck after 2-3 hours :(
I have this camera which is controlled by touch inputs, 1 finger is moving (when you swipe left, the camera goes right, so the whole scene should go left), 2 fingers is rotating (this works).
But when the camera is rotated, the 1 touch swipe is still in world space (or something), It has to react to the camera's forward direction.
if (touch.phase == TouchPhase.Began)
{
startInput = touch.position;
}
if (touch.phase == TouchPhase.Moved)
{
//1 finger down to move screen
if (Input.touchCount < 2)
{
targetPos = transform.parent.position + new Vector3(startInput.x - touch.position.x, 0, startInput.y - touch.position.y);
}
}
This is in the update:
transform.parent.localPosition = Vector3.Slerp(transform.parent.localPosition, targetPos, 4 * Time.deltaTime);
transform.parent.rotation = Quaternion.Slerp(transform.parent.rotation, targetRot, 4 * Time.deltaTime);
Any idea what I have to multiple/add/substract from the basic input in order to get the same movement even when the camera's rotated?
Check this (Unity3D Documentation) apply it to the Vector3(startInput.x - touch.position.x, 0, startInput.y - touch.position.y) part
Ye that did the trick lol. Before I asked this question I tried to apply it to the motion directly, and that failed. Thanks!
Please, could you post the final relevant code as an answer??? So others can find the solution.Greetings!!!
If you could do that, I can accept your answer and give you the points you diserve :)
Your answer
Follow this Question
Related Questions
Rotating a direction Vector3 by Quaternion 2 Answers
How do I rotate an object to face a direction. 1 Answer
Finding the difference between two directions? 0 Answers
Creating Hint Vector 1 Answer