- Home /
Question by
florivault · Feb 25, 2018 at 11:06 PM ·
mobiletouchtransform.translate
unity 3D mobile movement
Hello every body.
i have a problem, i wanted to translate 3D movement from PC to Mobile. firstable, i dont use any virtual joystick and canvas.
my character follow the delta position of my finger on the screen. it works well but it does not update every frame. i mean, my character move and stop in the direction of my finger.
i want my character move to the direction of my finger until i put my finger up.
here is my code :
void Update(){ Mouvement (); }
void Mouvement(){
if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Moved) {
Vector2 touchDeltaPosition = Input.GetTouch (0).deltaPosition;
float moveHorizontal = speed * touchDeltaPosition.x;
float moveVertical = speed * touchDeltaPosition.y;
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
transform.Translate(movement * speed * Time.deltaTime, Space.World);
if (movement != Vector3.zero)
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement.normalized), 0.2f);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612153432im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Delta touch trembling 0 Answers
Turning touch to rotation 1 Answer
The joystick isnt working in Unity remote 5 3 Answers
Moving a GUI Image to the same position as a touch 0 Answers