Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 nathaniel · Aug 30, 2010 at 02:22 AM · camera3dcamera-movement

Keeping two or more objects in a camera's view.

I am making a fighting game where the player and the opponent move around in 3D space, as opposed to 2D space as with a normal fighting game. I need the camera to always have the player and the opponent in view. So far, I have created a sphere that updates its position to always be in the exact middle between the player and his opponent, and have my camera looking at that.

I can't figure out how to zoom out when a character moves out of the camera's view or how to zoom it back in when a character moves closer to the opponent. I also need it to rotate in an appropriate manner when one character is above/below another.

I guess the closest thing I can think of for an example would be the camera in Dissidia Final Fantasy.

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

1 Reply

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

Answer by BoredKoi · Aug 31, 2010 at 06:12 AM

Phew, nothing like trig to keep the mind going far too late. Anyway, I'll give this a shot for a solution at least in the horizontal plane. I think this could easily be expanded to handle additional vertical offsets. But onwards:

Given Characters A and B, Sphere S, and Camera C:

A -- S -- B

 C

What we need to do is solve for the distance between S and C every update cycle, AND keep the our angles constant as far as the camera field of view is concerned (i.e., when you set your scene, you are saying that each character visually will be offset by X degrees from center). Some Mathf.Clamping will be necessary for the boundary situations but this -I think- will get you fairly close to the desired result:

  1. Start with the centered sphere looking at one of the players (B in this example)
  2. Parent the camera to the sphere, and have the camera looking at the sphere
  3. As the players move and the sphere is re-centered, "looks", and rotates, that will swing the camera in an arc and maintain the 90 degree A-B / S-C angle.
  4. Run the following calculation (in this example, from the perspective of player B)
  5. ( Vector3.Distance(S,B) * Mathf.Sin(Vector3.Angle(S,C) ) / Mathf.Sin(X) << note our constant "X" offset angle here
  6. Set that as the camera distance from the sphere

For reference, the formula above is the Law of Sines, just solved for our S->C distance.

This is totally untested, but I think the approach is right. Hope it helps. I'll be trying it out in the AM myself!

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 nathaniel · Aug 31, 2010 at 08:27 PM 0
Share

Thank you for the detailed answer! I will try to implement this when I get a chance to work on it next.

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

No one has followed this question yet.

Related Questions

Camera Shake Effect When Camera Following Player 1 Answer

Click and Drag 3D Camera, like Anno 1 Answer

Jerky 3rd Person Camera Following Movement and Rotation 0 Answers

Moving between two cameras 1 Answer

Panning camera based on a fixed point. 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