I need to create camera movement tracking the clipper hair like this:
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(){ try { 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); else localForwardDir = Vector3.Lerp(localForwardDir, Vector3.Cross(hitInfo.normal, LocalRightDir), Time.deltaTime * smoothTime); LocalRightDir = Vector3.Lerp(LocalRightDir, Vector3.Cross(-localForwardDir, hitInfo.normal), Time.deltaTime * smoothTime); } else { 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); else 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); }}