-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Add Transform Helper methods #15200
base: main
Are you sure you want to change the base?
Add Transform Helper methods #15200
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
/// - `speed`: A `f32` representing the speed at which the entity should move. | ||
/// - `delta_time_seconds`: A `f32` representing the time elapsed in seconds, typically | ||
/// the time since the last frame. | ||
pub fn translate(&mut self, direction: Vec3, speed: f32, delta_time_seconds: f32) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should merge direction
and speed
into a single velocity: Vec3
, else we're adding redundant ways to specify speed.
Alternatively if we really want to separate direction and speed (which in my opinion is not a necessary requirement since we multiply them back together anyway). It'd be best to use a Dir3
type for the direction, as it ensures the direction vector is normalised (length 1).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do like your suggestion to be honest.
Didn't think about using the velocity as the result of the multiplication of direction and speed.
Going to implement that straight away!
Refactored the two methods to accept a single Vec3 as the result of the direction Vec3 multiplied by the speed of the entity we are trying to move. This should remove the redundant assegnation of the speed.
Overall I think the code is good, I'm not sure on the naming though. Not sure what would be a better name. |
I see what you mean. Maybe to make it more coherent might be better to only have a Vec3 as the signature of the method, calling it translation and let the user create the translation vector by multiplying it by the speed AND the delta time? |
Going to change it later to only receive a Vec3 |
Objective
Solution
translate(&mut self, direction: Vec3, speed: f32, delta_time_seconds: f32)
. This function simply provides a faster way of adding a translation to the Transform by providing a direction, a speed and a delta_seconds (or delta in general referring to time). This doesn't take in account the rotation of the Transform.translate_with_local_rotation(&mut self, direction: Vec3, speed: f32, delta_time_seconds: f32)
. This function differs from the one above because it also utilizes the rotation of the Transform to provide a way of moving the object following a specific direction and taking in account also it's rotation.Testing
translation.rs
using the newly implemented functiontranslate
to see if the result was the same.translate_with_local_rotation
by modifing the example3d_rotation
and adding a new line just after the rotation. It moved as expected, but the addition of the line felt like out of scope of the example, so I removed it.