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 girlinorbit · Nov 21, 2019 at 08:28 PM · cameracamera-movement

Make Camera Follow Another GameObject

I've done quite a bit of research on this and haven't been able to find anything about this.

I have two GameObjects which in instated when the user logs in: the first is the player and the second is a horse, depending on what horse the user has. When the user mounts the horse, it switches cameras for usability's sake. When the user mounts the horse, the camera follows the horse specifically, but it is not a child of the horse because it's not smooth. Here is the hierarchy of one of the prefabs (they're all alike):

![alt text][1]

When the user first mounts, the view is something like this:

![alt text][2]

After the user starts turning, I get this:

![alt text][3]

I want the camera to be centered like it was when the user first mounted the horse. This is how I currently make the camera follow the horse:

 //THIS SCRIPT IS ATTACHED TO THE HORSE DIRECTLY
 transform.position += transform.forward * speed * Gait * Time.deltaTime;
 horseCamera.transform.position += transform.forward * speed * Gait * Time.deltaTime;
 horseCamera.transform.Rotate(0, Input.GetAxis("Horizontal"), 0);
 

If any of this doesn't make sense I'll try to explain it better.

Thanks in advance! [1]: http://photos.app.goo.gl/MWYXW7zriY9JgjkK9 [2]: https://photos.app.goo.gl/edvm94hEMfqyueE39 [3]: https://photos.app.goo.gl/76S5JNR9UMbr7Yoe7

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 Ermiq · Nov 25, 2019 at 11:27 AM

You say the horse camera is not a child of the horse but at the first picture the Camera object is actually a child of the Horse_White.


What is the object the script you've posted is attached to? If you have the script attached to the Horse_White then you move the whole Horse_White object with all its children by the script, therefore your camera will move too and you don't need to move the camera in the script then. By changing camera position in this case you make it go away off the horse and that's why you get this offset.


Another option: you have the script attached to the Horse object which is a child of the Horse_White. You shouldn't do that. You should only move the root object in the hierarchy (the parent, Horse_White in your case). By moving just the Horse you leave the parent at the place where it was at the start, and it's another reason why you could get this offset, because you move Horse (along with Armature) but your root object doesn't move and your camera doesn't move with the root as well. You forcibly move the camera in the script by changing its position property so it gets offset from the root and from the Horse as well (if their position changes are not calculated exactly the same way). And even if you have the same code for Horse moving and camera moving it still doesn't mean that they will move similar ways.


See, there are different position types. position and localPosition. position is a position of an object relative to the world coordinates (i.e. the whole scene), while localPosition is a position relative to the parent game object.

When you move an object that has no parents, you actually move this object and all its children. Its children localPosition is not changing in this case, if you place the camera behind the horse and just move the Horse_White the camera will follow and will stay behind the horse.

When you move a child by changing its position you actually move it away from the parent, in world coordinates system, and you change its localPosition relative to the parent as well.

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

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

TPS camera in multiplayer... 2 Answers

How do I get my camera to rotate around the y=0 coordinate it's looking at? 0 Answers

Vuforia camera frustum out of view after image target is lost 0 Answers

I can not find Cinemachine in package manager. There is no option of 'All Assets in package manager.' 1 Answer

Camera movement stuttery with interpolate on,Camera movement with interpolate on? 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