Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use getElapsedTime on the main state clock, it messes up the delta #2341

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

AlaricBaraou
Copy link
Contributor

@AlaricBaraou AlaricBaraou commented Feb 10, 2025

A very simple PR

Just used the Cloud component and I noticed it messed up 'the time'

I then saw that many components call clock.gelapsedTime() on the main clock instead of reading the .elapsedTime property

Calling getElapsedTime() update the delta of the clock and then returns .elapsedTime

Clock source in three.js
https://github.com/mrdoob/three.js/blob/master/src/core/Clock.js

Edit: In case you want the elapsed time precisely at the moment of the method call, use a separate clock for that.
I'd add that in 99% of case, you want the same elapsed time for all object in the current frame, making reading .elapsedTime even better than clock.gelapsedTime() to fully sync everything.

This could be added to the gotcha section of the doc because I come across this issue in most projects I review.

Copy link

vercel bot commented Feb 10, 2025

@AlaricBaraou is attempting to deploy a commit to the Poimandres Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

codesandbox-ci bot commented Feb 10, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants