Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Stepepper · Nov 30, 2017 at 09:54 AM · camerathird-person

Camera - Keep two objects on the screen while staying behind another

Hello everyone. I'm pretty stuck with something. I'm doing a school assignment where we have to recreate 10 seconds of a game. I have to recreate Kingdom Hearts, a fight between Wakka and Sora.

I'm stuck with the camera though, it rotates with the player, while looking at the middle of the two characters.

I've got a way figured out, but right now there are a couple problems.

  1. When the camera reaches the location where it has to look, it pretty much breaks and turns 180 degrees every frame, not moving to any direction.

  2. The camera moves at a constant speed when the player is out of bounds, this means that it's really stuttery.

While this method works in a way, it doesn't feel good at all, since it's so stuttery.

Here's the code I use:

 void LateUpdate ()
     {
         var lookAtPoint = target1.position + target2.position;
         lookAtPoint.x /= 2;
         lookAtPoint.y /= 2;
         lookAtPoint.z /= 2;
 
         Vector3 velocity = new Vector3();
         
         // horizontal movement
         Vector2 screen = Camera.main.WorldToScreenPoint(target1.position);
         float w = screen.x / Screen.width;
         if (w < horizontalBounds) velocity.x = -_cameraSpeed;
         else if (w > 1 - horizontalBounds) velocity.x = _cameraSpeed;
 
         // vertical movement
         Vector3 vectorToPlayer = target1.position - transform.position;// - target1.position;
         float distance = Vector3.Project(vectorToPlayer, transform.forward).magnitude;
         if (distance > maxDistance) velocity.z = _cameraSpeed;
         else if (distance < minDistance) velocity.z = -_cameraSpeed;
         
         Vector3 vel = transform.right * velocity.x * Time.deltaTime 
                       + transform.forward * velocity.z * Time.deltaTime;
 
         wantedPosition += vel;
 
         transform.position = Vector3.Slerp(transform.position, 
             wantedPosition, Time.deltaTime * _cameraSpeed);
 
         transform.LookAt(target2);
     }


Is there a way to fix this, or a better way to do this? Thanks in advance.

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

Answer by text23d · Nov 30, 2017 at 06:30 PM

maybe try going to Animation tab, make a new animation there for your camera, and try playing with variables like position, rotation of your camera. and don't forget to press 'record' button. also try https://www.assetstore.unity3d.com/en/?&_ga=2.140184123.92653374.1512065481-54233751.1511523262#!/content/79898

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

112 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 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 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 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

How do I make a third person camera toggle that doesn't snap? 0 Answers

3rd Person Camera Collision 4 Answers

Multiple clip exceptions for a camera. 1 Answer

problem with a third person camera 1 Answer

[SOLVED] Camera jitters while moving towards/away from player 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