Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 /
  • Help Room /
avatar image
0
Question by slims · Mar 25 at 04:34 AM · camera follow

Jittery movement with camera following player

I'm working on a game similar to Factorio. The camera is locked to the player while the player navigates around the world. The camera is updated to the player's position (minus some offset and zoom level) in LateUpdate. Player movement feels buttery smooth.


However, the player has a swarm of ships that follow it, and these ships experience a lot of jitter. The jitter goes away if I stop the camera from moving. I've tried different camera movement strategies (lerp, moveTwards, SmoothDamp), none of these work. Probably because there is some more fundamental solution to this problem involving the movement of the swarm around the player. Nothing uses physics bodies (or rigidbodies). I'm just updating positions of everything directly on their translation/transform.


Here is a demonstration of the problem:

https://www.youtube.com/watch?v=JoXCGZDGrIM


Here's the camera code:

       var dirVector = DirectionBuilder.Create(Direction).Vector; // Vector representing up, down, left or right, depending on camera rotation
       var followObjectPosition = _followObject.position;
       
       var basePos = new Vector3(
         followObjectPosition.x - dirVector.x * _cameraZOffset,
         _cameraHeight,
         followObjectPosition.z - dirVector.z * _cameraZOffset);
       
       transform.position = basePos + (_followObject.transform.position - transform.position).normalized * _zoomFactor;


Pretty basic stuff. The swarm movement code is fairly complex to make their movement feel natural, but I need a solution that will allow arbitrary entities following the player to move with the player at around the same speed as the player, without jittering (might be worth noting that my game is DOTS, the player is the only thing in the game that has a monobehaviour. The swarm around the player are all pure entities).

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 slims · Mar 25 at 07:31 PM

I fixed this bug but it's specific to people using DOTS. The problem was that the player being the only monobehaviour also has the mesh renderer attached to the monobheaviour. The camera is set to follow that monobehaviour's transform position. However, there is some discrepancy in LateUpdate between a monobehaviour's transform.position and an Entity's translation; they are not synced.

So the fix was to put the mesh renderer of the player on the player entity (where it should have been anyway), and have the followObject be the player entity's translation component instead of the monobehaviour. Since all the translations are updating in the same system, the camera follow is now synced to the entity component system's translations. Now all the motion is buttery smooth.

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

180 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

Related Questions

Does anyone know the script for a smooth camera follow of the main game object? 8 Answers

Trying to turn the Tank Game Camera script into perspective projection. 1 Answer

CAMERAS ERROR , I NEED HELP 0 Answers

Isaac's camera tracking 0 Answers

Camera not following properly with lerp 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