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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by miloyun · Mar 19, 2013 at 04:20 PM · cameralookatfollow

Camera Follow Object While Looking At Other Target

I have a sphere object that can freely move around which I can easily follow with the camera. (This is easy) The sphere object needs to be moved to a certain position for the player to earn score. (This is easy) I can follow the sphere with the camera while looking at the target position. (This is easy too.)

Basically I just added a follow script to the camera and targeted the sphere then added LookAt code to the script that makes the camera look at the target position.

The part that I haven't been able to figure out is:

Always have the freely rolling around sphere between the camera and the target position. So the player is able to see the sphere and target at all times. While the sphere is rolling around freely the player has no control over the sphere's movement. (A bit like billiards)

I have added a dummy object inside the sphere to get the rotation of the lookat value of the Y axis and copied that to the camera's Y axis. This helps but the sphere is cant be seen after the ball passes by the target and the angle is too much as there is a set distance between the camera and the sphere.

alt text

Any ideas? I am lost to how to calculate the relative position of the camera to the sphere while looking at target.

unity_question.png (13.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

2 Replies

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

Answer by robertbu · Mar 19, 2013 at 04:51 PM

Say you have the game objects of the target, the sphere and the camera. You can calculate a position that will keep them in a row as follows:

 var v3T = sphere.transform.position - target.transform.position;
 camera.transform.position = sphere.transform.position + v3T.normalized * camera_distance;

where camera_distance is the distance you want between the camera and the sphere.

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
avatar image
0

Answer by miloyun · Mar 20, 2013 at 09:09 AM

robertbu your solution works like a charm. Much faster than SmoothFollow for sure and easy to customize! Thanks...

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 Chronos-L · Mar 20, 2013 at 09:12 AM 0
Share

If @robertbu's answer have helped you, mark it as correct.

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

11 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

Related Questions

Camera follow in c# 1 Answer

Camera to smoothly LookAt() a series of empty objects along a curved path that act as a 'rail' 3 Answers

Making a camera that follows a rigidbodied sphere. 2 Answers

Camera following/looking at aircraft 1 Answer

Can anyone please tell me why this script doesnt work? - Raycasting 1 Answer


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