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 Teadaddy · Apr 22, 2015 at 05:38 PM · cameracamera rotatecamera-look

make a target camera?

I wonder if anyone might have a perspective on how to do the following- I have a series of targets to .LookAt given various UI or keyboard inputs. I want to set the camera to rotate the object looked at i.e Target Camera. However, when I move away from the target through WASD or LMB, I want the camera axis to return to the camera.

Any idears? Many Thanks!

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 Cherno · Apr 22, 2015 at 06:40 PM 0
Share

I have a hard time understanding what you wrote. Even if English is not your first language try to correct the grammar in your sentences. What does "I want to set the camera to rotate the object looked at i.e Target Camera" mean? Why should the camera rotate another object? Do you mean that the camera should rotate towards the object? Also, what does "I want the camera axis to return to the camera." mean?

avatar image Jessespike · Apr 22, 2015 at 07:23 PM 0
Share

He wants a camera that focuses onto objects, and when the objects are far away the camera will return to it's initial rotation.

http://answers.unity3d.com/questions/948832/foreach-loop-only-going-through-once-c.html

This guy had a similar problem, the camera doesn't return to it's original rotation when far away. But it should be enough to give OP an idea how to start and accomplish the problem. Also check out the StandardAssets, there's a follow camera script that should bring some insight.

avatar image Teadaddy · Apr 24, 2015 at 03:53 PM 0
Share

I apologize, I left out the word "around" as in "I want to set the camera to rotate around the object looked at, i.e a Target Camera" that is to say, I want to make the axis of the camera be the axis of the object it is looking at - the target- essentially making it a target camera, a camera which is looking toward the target as it rotates around it at a specific distance.

However when it (the camera ) is moved whether by WASD keys or by a mouse button press( I have the left mouse button set to move the camera forward, the right to rotate it) I want to make it more like a free camera, one that has it's axis centered in the camera, so that when it rotates it is simply turning in place.

$$anonymous$$akes sense?

Thanks for the link, Jessespike ,but not quite what I am looking for as I am not so much trying to focus on an object as make it the point around which the camera orbits, while always looking at it.

Thanks again for help offered.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by InfernoZYB · Apr 24, 2015 at 04:41 PM

This one was a little different but i have made a script for you! :D Hope it works to what you need it for and if you need help comment below.

 using UnityEngine;
 using System.Collections;
 
 public class LootAtTargetCamera : MonoBehaviour {
 
     Quaternion DefaultRotation;
     Vector3 Distance;
     public float maxdistance = 20;
     public GameObject camera;
     public GameObject target;
 
     // Use this for initialization
     void Start () {
         DefaultRotation = camera.transform.rotation;
     }
     
     // Update is called once per frame
     void Update () {
         //Debug.Log (Vector3.Distance (camera.transform.position, target.transform.position));
         if (Vector3.Distance (camera.transform.position, target.transform.position) <= maxdistance) {
             camera.transform.LookAt (target.transform);
         } else {
             camera.transform.rotation = DefaultRotation;
         }
     }
 }


Just put this script on and assign the camera and the target and the distance then it should work. Here is a preview of it(The "camera" is in the top corner but you can change that on yours):

alt text

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

22 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

Related Questions

Camera gets stuck when cursor is locked 0 Answers

Camera movement and gun follow in unity 1 Answer

Camera follow a sphere which look at another object on the ground 0 Answers

How to achieve a 3rd person camera for walk on planet games? 0 Answers

Camera isn't following mouse in FPS 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