Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by JaimeBGarcia · Mar 08, 2016 at 01:25 PM · cameracollisioncolliderterrain3rd person camera

My 3rd Person camera doesnt collide with Terrain... Please Help

Hi mates, im on Unity 5 and i am making a 3rd person game. I have a Player and a camera that has a CameraOrbit script to follow and turn around the player. This is the CameraOrbit script:

 using UnityEngine;
 using System.Collections;
 
 public class CameraOrbit : MonoBehaviour
 {
     public Transform target;
     public float distance = 10.0f;
     public float xSpeed = 5f;
     public float ySpeed = 2.5f;
     public float distSpeed = 10.0f;
     public float yMinLimit = -20.0f;
     public float yMaxLimit = 80.0f;
     public float distMinLimit = 5.0f;
     public float distMaxLimit = 50.0f;
     public float orbitDamping = 4.0f;
     public float distDamping = 4.0f;
     private float x = 0.0f;
     private float y = 0.0f;
     private float dist;
 
     void Start()
     {
         dist = distance;
 
         Vector3 angles = transform.eulerAngles;
         x = angles.y;
         y = angles.x;
 
         // Make the rigid body not change rotation
 
         if (GetComponent<Rigidbody>())
             GetComponent<Rigidbody>().freezeRotation = true;
     }
 
     void LateUpdate()
     {
         if (!target)
             return;
 
         Vector3 oPos = transform.position;
 
         x += Input.GetAxis("Mouse X") * xSpeed;
         y -= Input.GetAxis("Mouse Y") * ySpeed;
         distance -= Input.GetAxis("Mouse ScrollWheel") * distSpeed;
 
         y = ClampAngle(y, yMinLimit, yMaxLimit);
         distance = Mathf.Clamp(distance, distMinLimit, distMaxLimit);
 
         dist = Mathf.Lerp(dist, distance, distDamping * Time.deltaTime);
         transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(y, x, 0), Time.deltaTime * orbitDamping);
 
         transform.position = transform.rotation * new Vector3(0.0f, 0.0f, -dist) + target.position;
     }
 
     float ClampAngle(float a, float min, float max)
     {
         while (max < min)
             max += 360.0f;
         while (a > max)
             a -= 360.0f;
         while (a < min)
             a += 360.0f;
 
         if (a > max)
         {
             if (a - (max + min) * 0.5f < 180.0f)
                 return max;
             else
                 return min;
         }
         else
             return a;
     }
 }

It works well, but the problem is that my camera pass through the Terrain, it doesnt collide with it... I have checked a lot of scripts but i dont find the solution. Can anyone help me? But please be so specific because i am noob on Unity. I dont have any collider or anything on the camera because i dont think it is the problem... alt text Thank you so much mates :)

sin-titulo.png (515.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Terrain Spins when hit by player 1 Answer

About Camera Collision 2 Answers

How to move an object on a terrain that will always stay on top of the terrain? 2 Answers

How to make solid trees? 1 Answer

How to add avoid the script to overwrite camera collision? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges