• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by IKilledKenny_2 · Jan 02, 2015 at 10:15 PM · camerajavascriptcharacterfollow

Character Runs Off Camera

Hello Unity3D i have a problem with my camera.The problem is my characters camera is auto targeting an enemy and whenever my character runs too far I can still see the enemy but i can't see the character that i have attached the camera to.What i want is no matter how far i go the camera still shows my character and the enemy.If anyone knows how i can do t$$anonymous$$s.Can you please tell me how?

 var target : Transform;
 var moveSpeed = 20;
 var rotationSpeed = 5;
 var myTransform : Transform;
  
 function Awake() {
         myTransform = transform;
 }
  
 function Start() {
  
         target = GameObject.FindWithTag("Eye").transform;
 }
  
 function Update () {
    
     myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
     Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
 }
Comment
Add comment · Show 3
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 CrushBros · Jan 03, 2015 at 03:34 AM 0
Share

Wouldn't it be easier to set the transform in the inspector then trying to find a tag? And is your enemy tagged the same as your player?

avatar image IKilledKenny_2 · Jan 03, 2015 at 05:18 AM 0
Share

Well it finds the enemy automatically when the battle begins.So i thought this way was better no my enemy tag and my characters tags are totally different

avatar image CrushBros · Jan 03, 2015 at 10:24 AM 0
Share

So it changes target to the enemy from the player when it spots an enemy. Should probably enable a battle camera instead that has a higher view point and a bounding box that zooms the camera in and out when combat starts.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by rantor88 · Jan 04, 2015 at 04:28 AM

When using a script to have a camera follow an object, whether in first person or t$$anonymous$$rd, its always best to use LateUpdate rather than Update. LateUpdate occurs after update, and is best for tracking movement. I dont know if t$$anonymous$$s will stop the character from falling off the screen, but it might make a difference in camera lag.

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 IKilledKenny_2 · Jan 04, 2015 at 06:22 PM 0
Share

Hmmm...Intresting. What i was going to do was use the Var :ClampToScreen In order to make it that the character doesnt run off the camera.But alot of people tried and it didn't work for them.But ill try the LateUpdate instead.Thank You Very Much!

avatar image
0

Answer by makegoalken · Mar 04, 2020 at 08:09 AM

Your feedback helps me a lot, A very meaningful event, I hope everyt$$anonymous$$ng will go well enable flash in chrome

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

28 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

Related Questions

counting seconds that character is idle. 1 Answer

How can I tell Unity to wait to do something until after and animation has finished playing? 0 Answers

A node in a childnode? 1 Answer

How can I tell Unity to wait to do something until after and animation has finished playing? 1 Answer

Fixed camera on rails. 2 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