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 /
avatar image
0
Question by Ziron999 · Mar 01, 2017 at 07:14 AM · cameracollisioncollision detectioncamera-movementcamera follow

Top down camera lock

i have tried the solution in: http://answers.unity3d.com/questions/473917/how-to-prevent-camera-from-moving-through-meshes.html

my clip camera to the target so far is:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CameraClip : MonoBehaviour
 {
     [SerializeField]
     Transform target;
     float yoffset = 20;
     float xoffset = -10;
     float zoffset = -10;
 
     void LateUpdate()
     {
         transform.position = new Vector3(target.position.x + xoffset, target.position.y + yoffset, target.position.z + zoffset);
     }
 }

However, even though i have a collider and this clip on a parent to the main camera...the parent still goes right through collisions...the solution at the bottom of that link did not work. what is i missing to stop the camera from going through walls? I've uploaded a pic to show the problem alt text

untitled.png (522.4 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Ziron999 · Mar 01, 2017 at 09:27 AM

I have figured out a way to lock it myself:

     public float lockxmin;
     public float lockzmin;
     [SerializeField]
     float lockxmax;
     [SerializeField]
     float lockzmax;
     if (transform.position.x < lockxmin || transform.position.x > lockxmax)
             {
                 var temp = transform.position;
                 temp.x = Mathf.Clamp(temp.x, lockxmin, lockxmax);
                 transform.position = temp;
             }
             if (transform.position.z < lockzmin || transform.position.z > lockzmax)
             {
                 var temp = transform.position;
                 temp.z = Mathf.Clamp(temp.z, lockzmin, lockzmax);
                 transform.position = temp;
             }
Comment
Add comment · Show 2 · 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 HarshadK · Mar 01, 2017 at 11:13 AM 0
Share

This would restrict the camera to stay within a region specified by your $$anonymous$$ and max values not actually prevent the clipping issue of camera by it passing through other objects.

avatar image Ziron999 HarshadK · Mar 01, 2017 at 09:41 PM 0
Share

Right it essentially defines a map size which is all that's needed for the edges of terrain. The #1 issue is i can't clip terrain so I've been trying to find a way around that issue. That is why i had the question the way it is...Also the other answer only works for a 3rd person camera which is not what I'm doing either. It's top down like the title says. I tried to get it to work with my setup but can't do it. No matter what i do the clipping wouldn't work right.

avatar image
0

Answer by HarshadK · Mar 01, 2017 at 08:46 AM

It is passing through because you are setting the position directly via transform.position which will move the gameobject to that position ignoring the collisions. In Standard Assets there is a script called ProtectCameraFromWallClip to prevent wall clipping of camera which you can use.

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 Ziron999 · Mar 01, 2017 at 09:33 AM 0
Share

Although i found that CS file it is not that good on performance because it uses raycasting. However it is still an answer technically :)

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

91 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to rotate the camera with the player smoothly without the camera snapping back and forth? 2 Answers

Resetting Camera with a key input 1 Answer

Follow camera in 2d game 2 Answers

How to make a camera Follow an Object moving in zigzag path? 1 Answer

Gameobject flickers on camera follow. Solved but with silly method :/ 3 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