Math for Game Developers - Smooth Move(ment) (Linear Interpolation)

preview_player
Показать описание
Smooth out character movement by interpolating the velocity vector.

Рекомендации по теме
Комментарии
Автор

2020, Still the best tutorial in math for videogames

MrFrewq
Автор

10 Years later, this was the best tutorial I could find for the maths behind making a custom movement system with braking.

d.w
Автор

You did everyone a solid putting this playlist together. This is the bedrock of GD and a huge help! High praise good sir!

rorychockman
Автор

This is honestly probably the best video I've ever seen on YouTube. You explain everything super clearly. I wish I could like it more then once :D

gb
Автор

Yeah. There's lots of things that contribute to circle jumping making you a bit faster and this is probably the biggest one. You add the forward movement to the right movement and you get a vector that's longer than either forward or long, so you can move forward/right faster than only forward or right. It's not the lerping that causes it I would say but just adding vectors without normalizing them properly. Good thinking!

JorgeVinoRodriguez
Автор

If anyone is confused with what's going on with the dt*50
then considered using a variable. For ex: ( float step = dt*50 )
or more simply, dt (time in seconds) and 50 (speed in m/s), therefore dt*50 is (s * m/s = m)
It's just the step value.
If you want to go from 0 -> 5, then the function goes like 0 -> 0.5 -> 1 -> 1.5 -> 5 (in increments of 0.5, so step = 0.5)
so, it's nothing but distance coverage in small chunks.

PabitraPadhy
Автор

There are just no other tutorials on these topics, espacially of this quality. So thanks for helping out like 100 times now

lorddaikon
Автор

Thank you very much for the complete series. Now i am understanding how actually the gaming works.

karunakaran
Автор

Excellent series.
Straightforward style that is connected to the opposed to purely academic

MilesBellas
Автор

5 years later on a different account and going back through olde vids, here's another Unity/C# version I came up with (still took me embarrassingly long to figure it out, but oh well :P) :

public class Maths : MonoBehaviour
{
public static float Approach(float goal, float current, float dt)
{
//how far left to we have to go before we get to our goal
float difference = goal - current;
Debug.Log($"Goal: {goal}, Current: {current}, Diff: {difference}, DT: {dt}");

//--- interpolate up or down

//if dt is not enough to take us to our goal
if (difference > dt)
{
Debug.Log($"diff > dt. return {current + dt}");
return current + dt; //return one step further to our goal
}
/*edge case: if goal is lower than current (interpolating in the downward direction / value is getting lower),
then difference will be negative*/
if (difference < -dt)
{
Debug.Log($"diff < -dt. return {current - dt}");
return current - dt;
}

//otherwise, if in range of goal, return goal
return goal;
}
}

public class Game : MonoBehaviour
{
[SerializeField] float maxSpeedAbs;
float minSpeedAbs = 0;
[SerializeField] Rigidbody rbPlayer;

public VectorNew veloGoal;/
public VectorNew veloCurrent;
Vector3 rbVelo;

public void KeyRelease(float minSpeed)
{
if (Input.GetKeyUp("w"))
veloGoal.z = minSpeed;

if (Input.GetKeyUp("s"))
veloGoal.z = minSpeed;

if (Input.GetKeyUp("d"))
veloGoal.x = minSpeed;

if (Input.GetKeyUp("a"))
veloGoal.x = minSpeed;
}

public void KeyPress(float maxSpeed)
{
if (Input.GetKey("w"))
veloGoal.z = maxSpeed;

if (Input.GetKey("s"))
veloGoal.z = -maxSpeed;

if (Input.GetKey("d"))
veloGoal.x = maxSpeed;

if (Input.GetKey("a"))
veloGoal.x = -maxSpeed;

}

public void Update()
{
KeyPress(maxSpeedAbs);
KeyRelease(minSpeedAbs);
}

public void FixedUpdate()
{
veloCurrent.z = Maths.Approach(veloGoal.z, veloCurrent.z, Time.deltaTime * 40);
veloCurrent.x = Maths.Approach(veloGoal.x, veloCurrent.x, Time.deltaTime * 40);

if (veloCurrent.x > 0)
{
Debug.Log($"VeloCurrent.x: {veloCurrent.x}");
Debug.Log($"VeloCurrent.x * dt: {veloCurrent.x * Time.deltaTime}");
}
//(set the VectorNew into a Vector3)
rbVelo = new Vector3(veloCurrent.x, 0, veloCurrent.z);

rbPlayer.position += rbVelo * Time.deltaTime;
}
}

TheFingledorf
Автор

This is an underrated series! I subscribed immediately because of it!

sidgeek
Автор

Usually, you have a direction vector (normalized one) which is controlled by the input - while the speed is then used to stretch the direction vector. So simple: (note: .... represents other code)
....
incomingInput );
....
.... Inside Update
+ object.dir() * object.velocity());
....

where dir, velocity and positon are math-vector-N structs

this mostly prevents stuff like x, z-movement faster than x-movement

HatiEth
Автор

to make the project compile in VS 2013
it just require to add 
#include <memory>

in source files/renderer/shaders.cpp
(line 21 for example)

UTubeK
Автор

You have a great teaching style. I find these very enjoyable to listen to for a refresher.

MrGameengineer
Автор

Lerp = Linear Interpolation, awesome video dude! Thanks!

fernandoedelstein
Автор

wow, the way i've been doing it all this time is something like
velocity += (goal-velocity) / 20;
nice to learn that there's a better way to do these things

FunOrange
Автор

Super helpful tutorials. Keep up the good work mate

j.jester
Автор

btw Lerp stands for linear interpolation :)

temps
Автор

Thank you so much, you make me feel more comfortable with this algorithms, thanks my friend.

thangphan
Автор

It's the edit and continue feature in Visual Studio, the keyboard shortcut is Alt-F10. :)

JorgeVinoRodriguez