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

"smooth_damp" functions for primitives and math structs #13408

Open
vveisard opened this issue May 17, 2024 · 6 comments
Open

"smooth_damp" functions for primitives and math structs #13408

vveisard opened this issue May 17, 2024 · 6 comments
Labels
A-Animation Make things move and change over time A-Math Fundamental domain-agnostic mathematical operations C-Enhancement A new feature S-Needs-Design This issue requires design work to think about how it would best be accomplished

Comments

@vveisard
Copy link

What problem does this solve or what need does it fill?

I need to smoothly move a value towards a target value over time using velocity and other parameters (see below).

What solution would you like?

I would like a set of "smooth_damp" functions for primitives and which have:

  • current
  • target
  • velocity
  • smooth time
  • max value delta
  • time delta

Importantly, I would also like a spherical smooth_damp for Vec2 and Vec3.

What alternative(s) have you considered?

A similar effect can be achieved using interpolation functions while updating the start value. However, this lacks all the parameters of a smooth_damp function.

Additional context

https://docs.unity3d.com/ScriptReference/Vector3.SmoothDamp.html

@vveisard vveisard added C-Enhancement A new feature S-Needs-Triage This issue needs to be labelled labels May 17, 2024
@alice-i-cecile alice-i-cecile added A-Math Fundamental domain-agnostic mathematical operations A-Animation Make things move and change over time S-Needs-Design This issue requires design work to think about how it would best be accomplished and removed S-Needs-Triage This issue needs to be labelled labels May 18, 2024
@alice-i-cecile
Copy link
Member

I definitely want this: very useful!

This feels like something that could be added as an auto-implemented method on the Animatable trait. Does that make sense to you?

You would probably need to special case the spherical interpolation in some form. Perhaps a newtyped Vec2/Vec3 that captures the notion of operating in spherical coordinates?

@IQuick143
Copy link
Contributor

Perhaps a newtyped Vec2/Vec3 that captures the notion of operating in spherical coordinates?
How about a Dir2/3, it's already a newtyped Vec2/3, bound to the unit sphere.

@alice-i-cecile
Copy link
Member

Dir2 and Dir3 are a great primitive for this, and interpolating them should definitely be on the surface of the n-sphere. I think that's probably enough actually, as long as we have an example that shows how to use those interpolation methods to create a spherical path around a center between two points.

@SIGSTACKFAULT
Copy link
Contributor

If Dir3 gets it then Quat should too

@vveisard
Copy link
Author

This feels like something that could be added as an auto-implemented method on the Animatable trait. Does that make sense to you?

Yes, Animatable seems like the right place for a smooth_damp method. However, I would expect a smooth_damp method for f32, Rotation2d, Vec2, Vec3, Dir2, Dir3, and Quat, and some of those lack an Animatable implementation.

I'm not familiar enough with Rust to know if auto-implement is the right thing to do.

@alice-i-cecile
Copy link
Member

Pretty much all of those should have an Animatable implementation :) But yes, this can just be a method on the trait with a default implementation of the method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Animation Make things move and change over time A-Math Fundamental domain-agnostic mathematical operations C-Enhancement A new feature S-Needs-Design This issue requires design work to think about how it would best be accomplished
Projects
None yet
Development

No branches or pull requests

4 participants