I need to create camera movement tracking the clipper hair like this:

Animated gif of hair being buzzed in a barbershop game

I already have a script for the movement of the tool.

  • I'm using Snapping Player to the Surface of an Object of this pos How could I constrain player movement to the surface of a 3D object using Unity?

      private void UpdatePlayerTransform(Vector3 movementDirection){
      if (GetRaycastDownAtNewPosition(movementDirection, out hitInfo)){
          Quaternion targetRotation = Quaternion.FromToRotation(Vector3.up, hitInfo.normal);
          finalRotation = Quaternion.RotateTowards(transform.rotation, targetRotation, float.PositiveInfinity);
          transform.rotation = Quaternion.Lerp(transform.rotation, finalRotation, Time.deltaTime * smoothTime);
          transform.position = Vector3.Lerp(transform.position, hitInfo.point + hitInfo.normal * .08f, Time.deltaTime * smoothTime);
      private bool GetRaycastDownAtNewPosition(Vector3 movementDirection, out RaycastHit hitInfo)
          Vector3 newPosition = transform.position;
          Ray ray = new Ray(transform.position + movementDirection * Speed, -transform.up);
          if (Physics.Raycast(ray, out hitInfo, 1f, WorldLayerMask))
              return true;
          return false;


  • I'm find move director

      void FindMovementDirVector(){
          float angle = Vector3.Angle(hitInfo.normal, Vector3.up);
          float angleWithForward = Vector3.Angle(hitInfo.normal, Vector3.forward);
          if (angleWithForward < 90 && angle < 60)
              caseName = "Case 1";
              if (angleWithForward > 30)
                  localForwardDir = Vector3.Lerp(localForwardDir, Vector3.Cross(hitInfo.normal, -Camera.main.transform.right), Time.deltaTime * smoothTime);
                  localForwardDir = Vector3.Lerp(localForwardDir, Vector3.Cross(hitInfo.normal, LocalRightDir), Time.deltaTime * smoothTime);
              LocalRightDir = Vector3.Lerp(LocalRightDir, Vector3.Cross(-localForwardDir, hitInfo.normal), Time.deltaTime * smoothTime);
              caseName = "Case 2";
              Vector3 to = new Vector3(hitInfo.normal.x + hitInfo.point.x, hitInfo.point.y, hitInfo.normal.z + hitInfo.point.z);
              if (angleWithForward > 35)
                  LocalRightDir = Vector3.Lerp(LocalRightDir, Vector3.Cross(to, Vector3.up), Time.deltaTime * smoothTime);
                  LocalRightDir = Vector3.Lerp(LocalRightDir, -Vector3.Cross(to, Vector3.up), Time.deltaTime * smoothTime);
              localForwardDir = Vector3.Lerp(localForwardDir, -Vector3.Cross(hitInfo.normal, LocalRightDir), Time.deltaTime * smoothTime);
      catch { }
    • Input script

        private void TouchInput(){
        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
            pointer_x = Input.touches[0].deltaPosition.x;
            pointer_y = Input.touches[0].deltaPosition.y;
            if (pointer_x > 0)
                movementDirection += LocalRightDir * pointer_x;
            else if (pointer_x < 0)
                movementDirection -= LocalRightDir * Mathf.Abs(pointer_x);
            if (pointer_y > 0)
                movementDirection += localForwardDir * pointer_y;
            else if (pointer_y < 0)
                movementDirection -= localForwardDir * Mathf.Abs(pointer_y);
  • \$\begingroup\$ Like what? The user can move it like that? Automatically? Tracking the tool? \$\endgroup\$
    – Zibelas
    Commented Feb 23 at 9:44
  • \$\begingroup\$ That's a simple orbiting camera. Also, UnityScript is deprecated. \$\endgroup\$
    – liggiorgio
    Commented Feb 23 at 10:07
  • \$\begingroup\$ Hello @Zibelas! sorry for my mistake. I want camera automatically tracking the tool \$\endgroup\$
    – Lưu Anh
    Commented Feb 23 at 10:57
  • \$\begingroup\$ Is the tool restricted to the top/back of a head exactly as shown here, or do you have any other scenarios it needs to handle? Be sure to read the tag descriptions too — you probably want an answer in C# unless you're using a decade-old Unity version that still has UnityScript in it. \$\endgroup\$
    – DMGregory
    Commented Feb 23 at 12:04
  • 1
    \$\begingroup\$ @Pow Presumably Lưu Anh does not know how to implement it, or they would not have posted this question. \$\endgroup\$
    – Kevin
    Commented Feb 23 at 18:23

1 Answer 1


Personally, I would add an empty game object in the middle of the head and have the camera always LookAt() it. Then place another empty game object, as a child of the clippers, and have your camera always move towards it, probably using Vector3.SmoothDamp() (as it will give a bit of easing to the camera movement).


  • \$\begingroup\$ This approach would not achieve the look in the example GIF. The camera doesn't move as far as the clippers. Also, Vector3.SmoothDamp() moves in a straight line, which often isn't desirable for an orbit camera because it won't maintain the same orbit distance. \$\endgroup\$
    – Kevin
    Commented Feb 23 at 23:45
  • \$\begingroup\$ Thanks you! I tried. But it doesn't work like that. \$\endgroup\$
    – Lưu Anh
    Commented Feb 26 at 2:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .