Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Lunas Lama · Aug 30, 2014 at 04:16 AM · camerathird-personflickering

Camera flickering when rotating around object

Hi everyone. I really don't know why this happens. But for me it seems not to be a problem with the collision. In the following videos, there aren't any objects behind the camera. So why does this happen?

Please take a look:

https://dl.dropboxusercontent.com/u/2935685/unity/Unity%202014-08-29%2021-24-24-87.1.avi and https://dl.dropboxusercontent.com/u/2935685/unity/Unity%202014-08-29%2021-25-30-40.1.avi

The following script is what I'm using for the camera. I hope you guys can give me some tipps.

 var target : Transform;
 var distance = 10.0;
  
 var xSpeed = 150.0;
 var ySpeed = 100.0;
  
 var yMinLimit = 5;
 var yMaxLimit = 80;
  
 var distanceMin = 3;
 var distanceMax = 15;
  
 private var x = 0.0;
 private var y = 0.0;
  
  
 @script AddComponentMenu("Camera-Control/Mouse Orbit")
  
 function Start () {
     var angles = transform.eulerAngles;
     x = angles.y;
     y = angles.x;
  
     // Make the rigid body not change rotation
        if (rigidbody)
         rigidbody.freezeRotation = true;
 }
  
 function LateUpdate () {
     if (target) {
         x += Input.GetAxis("Mouse X") * xSpeed * distance* 0.02;
         y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
  
          y = ClampAngle(y, yMinLimit, yMaxLimit);
  
         var rotation = Quaternion.Euler(y, x, 0);
  
         distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel")*5, distanceMin, distanceMax);
  
         var hit : RaycastHit;
         if (Physics.Linecast (target.position, transform.position, hit)) {
                 distance -=  hit.distance;
         }
  
         var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
  
         transform.rotation = rotation;
         transform.position = position;
         
         //Hide the cursor
         Screen.showCursor = false;
  
     }
  
 }
  
  
 static function ClampAngle (angle : float, min : float, max : float) {
     if (angle < -360)
         angle += 360;
     if (angle > 360)
         angle -= 360;
     return Mathf.Clamp (angle, min, max);
 }

Comment
Add comment · Show 1
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
avatar image Lunas Lama · Aug 31, 2014 at 12:30 PM 0
Share

Can someone point me to a good tutorial for a collision detection? $$anonymous$$aybe it will solve this problem.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by SnotE101 · Sep 01, 2014 at 07:47 AM

http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html

or

http://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html

Good luck!

Comment
Add comment · Show 1 · Share
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
avatar image Lunas Lama · Sep 01, 2014 at 07:50 PM 0
Share

Well that isn't a tutorial and makes it more complicated for me.

avatar image
0

Answer by Lunas Lama · Sep 02, 2014 at 08:02 AM

I tried to add a camera bumper, but it's still not working. Here's the code: var target : Transform; var distance = 10.0;

 var xSpeed = 150.0;
 var ySpeed = 100.0;
  
 var yMinLimit = 5;
 var yMaxLimit = 80;
  
 var distanceMin = 3;
 var distanceMax = 15;
  
 private var x = 0.0;
 private var y = 0.0;
 
 
 ////////////////////////test
 var distance_bumper : float = 3.0;
 var height : float = 1.0;
 var damping : float = 5.0;
 var smoothRotation : boolean = true;
 var rotationDamping : float = 10.0;
  
 var targetLookAtOffset : Vector3;         // allows offsetting of camera lookAt, very useful for low bumper heights
  
 var bumperDistanceCheck : float = 2.5;    // length of bumper ray
 var bumperCameraHeight : float = 1.0;     // adjust camera height while bumping
 var bumperRayOffset : Vector3;         // allows offset of the bumper ray from target origin
 
 
 ////////////////////////////////
 function FixedUpdate() {
  
     var wantedPosition = target.TransformPoint(0, height, -distance_bumper);
  
     // check to see if there is anything behind the target
     var hit : RaycastHit;
     var back = target.transform.TransformDirection(-1 * Vector3.forward);    
  
     // cast the bumper ray out from rear and check to see if there is anything behind
     if (Physics.Raycast(target.TransformPoint(bumperRayOffset), back, hit, bumperDistanceCheck) 
               && hit.transform != target) { // ignore ray-casts that hit the user. DR
         // clamp wanted position to hit position
         wantedPosition.x = hit.point.x;
         wantedPosition.z = hit.point.z;
         wantedPosition.y = Mathf.Lerp(hit.point.y + bumperCameraHeight, wantedPosition.y, Time.deltaTime * damping);
     } 
      
 }
 
 ///////////////////end test
 
  
  
 @script AddComponentMenu("Camera-Control/Mouse Orbit")
  
 function Start () {
     var angles = transform.eulerAngles;
     x = angles.y;
     y = angles.x;
  
     // Make the rigid body not change rotation
        if (rigidbody)
         rigidbody.freezeRotation = true;
 }
  
 function LateUpdate () {
     if (target) {
         x += Input.GetAxis("Mouse X") * xSpeed * distance* 0.02;
         y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
  
          y = ClampAngle(y, yMinLimit, yMaxLimit);
  
         var rotation = Quaternion.Euler(y, x, 0);
  
         distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel")*5, distanceMin, distanceMax);
  
         var hit : RaycastHit;
         if (Physics.Linecast (target.position, transform.position, hit)) {
                 distance -=  hit.distance;
         }
  
         var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
  
         transform.rotation = rotation;
         transform.position = position;
         
         //Hide the cursor
         Screen.showCursor = false;
     }
 }
 
 
  
  
 static function ClampAngle (angle : float, min : float, max : float) {
     if (angle < -360)
         angle += 360;
     if (angle > 360)
         angle -= 360;
     return Mathf.Clamp (angle, min, max);
 }
Comment
Add comment · Share
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

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

Mathf.Clamp issues 1 Answer

3rd person camera reset bug 0 Answers

Third Person Camera Wall Covering Camera 0 Answers

Problem with mouse look and second skybox cam 0 Answers

3rd person clipping 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