can't rotate character in unity
don't know why it dosen't rotate as I intended... if mouse hit object tag with Finish, moveOn become true and character moveon....
void Update()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Input.GetMouseButtonUp(0))
{
if(Physics.Raycast(ray,out hit, Mathf.Infinity)){
Debug.Log(hit.collider.tag + "hit");
if (hit.collider.tag == "Finish")
{
targetPosition = hit.point;
targetRotation = Quaternion.LookRotation(transform.position - targetPosition);
moveOn = true;
}
}
}
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(transform.position - targetPosition), 3f*Time.deltaTime );
if (moveOn)
{
v1 = (transform.position- targetPosition).normalized;
//
Distancedir = Vector3.Distance(targetPosition,transform.position);
animator = GameObject.FindWithTag("Player").GetComponent<Animator>();
animator.SetBool("run", true);
transform.Translate(v1* Time.deltaTime * 7f) ;
}
Comment
Your answer
Follow this Question
Related Questions
getting an object to move only along x-axis and y-axis 0 Answers
GameObject doesn't move 1 Answer
Trying to work with Addforce to move my character 1 Answer
Make character move up on Y axis as apposed to move forward in Z space when mobile device is tilted 2 Answers
Character Movement on Cylinder Surface 0 Answers