Home > Net >  problem with move my 3D character with touch in unity
problem with move my 3D character with touch in unity

Time:02-02

I have a simple character and want to move it in Environment with touch. in each moment if player move his hand character compare the previous and current position of the hand and calculate a vector for move direction. writing this two class doesn't solved my problem.

I write this two class for character moving. touch class

void Update()
{
   if (Input.touchCount == 1)
   {
      PlayerTouch = Input.GetTouch(0);
      if (PlayerTouch.phase == TouchPhase.Moved)
      {
         MoveDirection.x = TouchDeltaPosition.x;
         MoveDirection.z = TouchDeltaPosition.y;
      }
      characterMove.Move(MoveDirection * 1000);
}

}

above class call the move function in CharacterMove class just like below

public void Move(Vector3 moveDirecion)
{
   transform.rotation = Quaternion.Lerp(transform.rotation, 
   Quaternion.LookRotation(moveDirecion), Time.deltaTime * Speed);
   transform.position  = transform.forward*Time.deltaTime * Speed2;
}

CodePudding user response:

In my Opinion you must use Transform.translate for your movement. after that with rotatetoward you can smoothly turn toward destination direction. why you comment those of this line in your movement script?

  • Related