Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 Khena_B · Jan 23, 2017 at 07:21 PM · camerasmoothpixelpixel artsnap

SmoothDamp and rounding problem

Hey,

I'm using Vector3.SmoothDamp to make my camera follow my player smoothly, it works perfectly, but i'm trying to round my camera's position so that it snaps to the pixels.

My code works fine in editor but when running the build with a much higher FPS, the cam is super jerky and fast.

There must be something i'm doing wrong, is anyone able to explain what is going on?

This is running in Update, why is it framerate dependent?

 Vector3 smoothedCam = Vector3.SmoothDamp(cam.transform.position, player.transform.position, ref velocity, camSpeed);
 
             cam.transform.position = new Vector3(Mathf.Round(smoothedCam.x * pixelsPerUnits) / pixelsPerUnits, Mathf.Round(smoothedCam.y * pixelsPerUnits) / pixelsPerUnits, cam.transform.position.z);
Comment
Add comment · Show 5
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 TreyH · Jan 23, 2017 at 08:21 PM 0
Share

Interesting, so what sort of "snap" behavior are you looking for? To end in an integer coordinate, or to move with integer coordinates entirely?

avatar image Khena_B TreyH · Jan 23, 2017 at 08:30 PM 0
Share

I want my camera to move pixels by pixels so that my game stays pixel perfect, with a Pixels Per Unit of 100 this would mean rounding the position to every 0.01 in world units.

But i still want the smooth behavior that SmoothDamp gives me.

I don't understand why rounding the smoothed out vector gives me different results at different framerates.

avatar image Khena_B · Jan 23, 2017 at 08:56 PM 0
Share

Hmm, could it be because the faster $$anonymous$$athf.Round is updating, the more "skips" i get to the nearest 0.01?

avatar image TreyH Khena_B · Jan 23, 2017 at 09:09 PM 0
Share

Hm, the documentation mentions that the referenced velocity value you supply will be modified with each call. Since the rounding you've set up should already be doing the "only move when a new pixel is available" behavior, this might be causing problems?

Is that being deter$$anonymous$$ed before this block is reached in Update, or is this function the only thing controlling it?

avatar image Khena_B TreyH · Jan 23, 2017 at 09:21 PM 0
Share

The same issue occurs with Lerp multiplied by deltatime so i'm not sure about SmoothDamp's velocity, the code i pasted is pretty much the only thing happening in the script other than setting my variables. I assumed that rounding the cam's position would have the same behavior than using SmoothDamp, but having it jump by 0.01 ins$$anonymous$$d, i don't understand the framerate affecting the speed only when rounding, it has to be the speed at which the rounding is updating making the cam move faster, my brain isn't cooperating today.

3 Replies

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

Answer by Khena_B · Jan 23, 2017 at 10:05 PM

Solved it by using SmoothDamp on a new Vector3, and instead made the camera follow this vector, then rounded the camera's position.

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
avatar image
0

Answer by Juandapp · Nov 21, 2019 at 05:44 AM

Hi, did you solve it? I have a similar problem with the camera and my FPS

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
avatar image
0

Answer by Siliko · May 21 at 05:16 PM

Turned nice rounding camera after smooth damp, help me a bit but not fixed yet

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

90 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

Related Questions

Preventing Objects from being pixelated in play mode. 0 Answers

Is there a way to pixelate a specific layer? 1 Answer

Pixel Perfect with Height constant 0 Answers

Can somebody please help me with my code - what do i need to add to make my camera turn SMOOTHLY towards the enemy? 2 Answers

How can I remove the red error text from Pixel Perfect Camera? 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