The official unity scripting manual describes the clip planes as: It sounds like you've misunderstood what a camera's near clip plane is. I have no idea how to fix this, if I make the nearClipping lower the whole render gets messed up, and even then it doesn't work, so what else can I do to ensure that the user never sees underneath the ground? The problem: as you can see in this pictureĮven with the low nearClipping value, and the high offsetFromWall value (0.7f when it's normally 0.1f), the camera is still clipping the ground when moving it with the mouse semi-fast (when it's moved kind of slow it's not a problem). Private float ClampAngle(float angle, float min, float max)Īs you can see in the start function, I also set the near clipping to a low value (the camera has a MainCamera tag BTW). If (targetRotationAngle = currentRotationAngle) XDeg = Mathf.LerpAngle(currentRotationAngle, targetRotationAngle, rotationDampening * ltaTime) Finally Set rotation and position of cameraįloat targetRotationAngle = įloat currentRotationAngle = Position = - (rotation * Vector3.forward * currentDistance + vTargetOffset) Recalculate position based on the new currentDistance If (pbuffer currentDistance ? Mathf.Lerp(currentDistance, correctedDistance, ltaTime * zoomDampening) : Mathf.Lerp(currentDistance, correctedDistance, ltaTime * zoomDampening * 3) ĬurrentDistance = Mathf.Clamp(currentDistance, minDistance, maxDistance) Don't do anything if target is not defined Only Move camera after everything else has been updated Target = GameObject.FindGameObjectWithTag("Player") as GameObject ![]() Private float coolDown = 0.5f //Cooldowntime for SideButtonsĬollisionLayers = LayerMask.GetMask("Default") Private float pbuffer = 0.0f //Cooldownpuffer for SideButtons Public bool allowMouseInputY = true // Allow player to control camera angle on the Y axis (Up/Down) Public bool allowMouseInputX = true // Allow player to control camera angle on the X axis (Left/Right) Public bool lockToRearOfTarget = false // Lock camera to rear of target Public int collisionLayers // What the camera will collide with Public float zoomDampening = 5.0f // Auto Zoom speed (Higher = faster) Public float rotationDampening = 3.0f // Auto Rotation speed (higher = faster) ![]() Public float zoomRate = 40f // Zoom Speed Public float yMaxLimit = 80f // Looking down limit Public float yMinLimit = -80f // Looking up limit Public float ySpeed = 200.0f // Orbit speed (Up/Down) Public float xSpeed = 200.0f // Orbit speed (Left/Right) ![]() Public float minDistance = 0.6f // Minimum zoom Distance Public float maxDistance = 20f // Maximum zoom Distance Public float offsetFromWall = 0.7f // Bring camera away from any colliding objects Public float distance = 12.0f // Default Distance Public float targetHeight = 1.7f // Vertical offset adjustment Public GameObject target // Target to follow Public class CameraController : MonoBehaviour Here is the documentation if you want to have a quick read on how to get started They also have a few videos on their YouTube channel which you might find helpful as well.Hi I'm trying to do a basic Camera Collision in unity, for convenience, here's the entire script (I actually got most of it from someone else who wrote the comments, if that's necessary to know): /// Unity has come out with a new Input System that is much better than the old one and comes with much more customisation. ![]() This code is also quite old as it uses the old Unity Input System. Transform.localRotation = Quaternion.Euler(xRotation, yRotation, 0f) XRotation = Mathf.Clamp(xRotation, -25f, 20f) YRotation = Mathf.Clamp(yRotation, -25f, 20f) PlayerBody.Rotate(Vector3.left * mouseY) using UnityEngine Ĭursor.lockState = CursorLockMode.Locked įloat mouseX = Input.GetAxis("Mouse X") * speed * ltaTime įloat mouseY = Input.GetAxis("Mouse Y") * speed * ltaTime Your final code would look something like this assuming you are going to change the second value the same way as the yRotation variable. Either way, to add another axis just add another variable and add it to the last line in your code. Looking at the documentation ( ), the first value is the x rotation so you are actually using the yRotation value to change the x rotation. Just add another variable ( float xRotation) and in the transform.localRotation = Quaternion.Euler(yRotation, 0f, 0f) change the second value to xRotation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |