-
How do I stop the flickering that occurs when the character stops moving?
over 8 years ago
-
over 8 years ago
For sure your code is not reaching to the end so that it can set the "walking" parameter false despite of the player reaching to the destination position.
So for the change don't run that part of code in "else" part inspite check it seperately.
-
-
over 8 years ago
void Update () { touched = true; if (Input.GetMouseButtonDown (0)) { Vector3 mousePosition = Input.mousePosition; mousePosition.z = 10; // distance from the camera target = Camera.main.ScreenToWorldPoint(mousePosition); target.z = transform.position.z; } var movementDirection = (target - transform.position).normalized; if (movementDirection.x != 0 || movementDirection.y != 0) { anim.SetBool("walking" , true); anim.SetFloat("SpeedX" , movementDirection.x); anim.SetFloat("SpeedY" , movementDirection.y); Vector2 movement = new Vector2( speed * movementDirection.x , speed * movementDirection.y); movement *= Time.deltaTime; transform.Translate(movement); if (movementDirection.x < 0) { anim.SetFloat("LastMoveX" , -1f); } else if (movementDirection.x > 0) { anim.SetFloat("LastMoveX" , 1f); } else { anim.SetFloat("LastMoveX" , 0f); } if (movementDirection.y > 0) { anim.SetFloat("LastMoveY" , 1f); } else if (movementDirection.y < 0) { anim.SetFloat("LastMoveY" , -1f); } else { anim.SetFloat("LastMoveY" , 0f); } } if(movementDirection.x == 0 && movementDirection.y == 0)//Try to check this condition weather it's getting to the target position or not. { touched = false; anim.SetBool("walking" , false); } }
-
2 Answer(s)