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
1
Question by Fire-Dragon-DoL · Jan 30, 2012 at 10:00 PM · cameramultiplayerlogic

Centering camera between 4 players

I'm trying to make a camera that will always target the "center" between 4 playes and zoom out if the distance between them increases (and zoom in when decreases).

I managed easily to get the center of those players, but I'm having a lot of problems with zoom in/out functionality expecially because I have to consider that a player me be also on a different height relative to the others.

Any help or links to tutorial is well appreciated

Edit 1 I'm asking also for a suggestion about how to calculate the center, my current idea is:

  1. Find the point between point1 and point2 (let's call it between1)

  2. Find the point between between1 and point3 (call it between2)

  3. Find the point between between2 and point4

The other idea I have is this:

  1. Find the point between point1 and point2 (between1)

  2. Find the point between point3 and point4 (between2)

  3. Find the point between between1 and between2

But with this, I'm having some hard times with 3 characters :\

Comment
Add comment · Show 2
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 DaveA · Jan 30, 2012 at 10:21 PM 0
Share

Is this a side-scroller or arbitrary 3d movement? The problem is somewhat easier if the players are always in the same plane. Otherwise your camera needs to find a comfortable distance that can exist from many different vantage points, so you'd have to provide more constraints.

avatar image Fire-Dragon-DoL · Jan 31, 2012 at 02:34 PM 0
Share

It's a 3D diablo-like game (I don't remember the name of that genrte). So people moves on the same plane, however they can be on different vertical axis, like if a stairs bring you a bit up, the camera should zoomout to let all characters fit the screen

2 Replies

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

Answer by Tasarran · Jan 30, 2012 at 10:37 PM

I would start the camera at the center you found, then zoom back a certain increment (you'll have to figure out what works for you)

Then check to see if the palyers are all visible, using Renderer.isVisible()

Then, if they are not visible, move back again and re-check.

You ought to be able to do this many times in a single Update, so you should only see the end result.

As a matter of fact, it would work better with a while() loop...

pseudocode!

 while ( All four players !(Renderer.isVisible)) {
     Zoom back;
 }
Comment
Add comment · Show 7 · 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 DaveA · Jan 31, 2012 at 12:45 AM 0
Share

I would suggest checking the renderer bounds, rather than isVisible. Wouldn't isVisible be true if any part, no matter how small, is visible? Or just the pivot point? The bounds will give you an idea of his total screen size, and you can add some padding for a border.

avatar image Fire-Dragon-DoL · Jan 31, 2012 at 02:24 AM 0
Share

Good suggestion, can you also suggest me "how" to detect the center? I have some ideas but I'm not sure of it (see my edit).

avatar image Tasarran · Jan 31, 2012 at 11:16 AM 0
Share

That's technically a second question, you should really accept this one as answered and ask another, but I'll answer it here :)

The easiest way I can think of is simply to find the average of the positions.

Just add all the transform.position values for all the characters, and divide by the number of characters.

Should work for any number of characters...

Or you can find the median, as opposed to the mean (average). This means that you would check all the positions, find the $$anonymous$$/max in all three coordinates, thereby building a bounding cuboid. Then just find the center of that cuboid. You can add a margin to make sure that the outermost chars aren't right on the edge of the screen.

$$anonymous$$edian method is probably the best.

avatar image Fire-Dragon-DoL · Jan 31, 2012 at 02:39 PM 0
Share

Well I wrote "centering" the camera and I hoped that the question was enough generic, but I don't have any problem in making a new question. The 2 methods you stated is those that I used 'till now when I tested them in game: the first one seems to not be the "center" when you look at it (the average). The median has the big problem of not considering the height (Y) of all players, so the camera doesn't zoom out enough most times. However, I have to test with your renderer.isvisibile method, I think it is ok if I use both of them.

avatar image Tasarran · Jan 31, 2012 at 02:41 PM 1
Share

You start zoomed in on the median, then zoom back until they are visible...

Shouldn't matter what axis they are more distant on, it should work...

Show more comments
avatar image
0

Answer by Berenger · Jan 30, 2012 at 10:28 PM

Once you have the center, your zoom should be given by the player the farthest from it, and that distance. Then you just push or pull the camera along forward.

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 Fire-Dragon-DoL · Jan 31, 2012 at 08:58 AM 0
Share

Read my edit, can you help with that if possible?

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

6 People are following this question.

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

Related Questions

2 players 1 game field in shooter/card game 0 Answers

Multiplayer click and spawn 1 Answer

TPS camera in multiplayer... 2 Answers

Have Camera Render First Person Arms But Not Body. 2 Answers

How to make camera position relative to a specific target. 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