-
Notifications
You must be signed in to change notification settings - Fork 44
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
Tweening position doesn't work. #26
Comments
How are you calling the code? The reason it doesn't work IIRC is because the object returned by getPosition is a temp variable object so changing the values in the object doesn't do anything. Whereas getLocalPosition returns the internal vec3 that the entity transform uses. To get around this, try using the custom update callback:
|
(PS Please don't @ directly to user unless it is very specific to that user. There are different team members and contributors that own different parts of the platform and codebase. I'm not in all of them) |
Ok sorry yaustar. Your solution worked. I think getPosition and getLocalPosition should work in the same way, should't it? This is confusing. |
It does require some knowledge about what is done under the hood to understand why the two are different. An entity stores a vec3 for it's local position and that is used to calculate where it's world position is. This is also return by getLocalPosition so directly editing the object that is returned from getLocalPosition will change it's position. getPosition returns a temporary calculated position vec3. Editing this directly doesn't do anything. And the root of all this is because JS can't pass or return by value with objects unlike C# and C++. The reason for all these temporary variables is to reduce garbage collection. Ideally the two should behave the same way and that getLocalPosition should also return a temporary vec3 instead of the one that it is actually using in the engine for the transform. That way, neither getLocalPosition or getPosition would work in the tween and both would have to use the update method instead. |
@yaustar The same code used to tween local position doesn't work for tweening position. It makes the UI element disappear. Use case: tween from top right corner to top left corner. Related forum post: https://forum.playcanvas.com/t/how-can-i-get-the-top-left-position-if-i-anchored-on-the-top-right/23007
The text was updated successfully, but these errors were encountered: