🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Just opened old project and need help understanding lmao

Started by
4 comments, last by Loomina 3 years, 5 months ago

Not sure if this is better suited in the math section or not (sorry if it is).

Yea so I just opened an old project I want to continue and I found some code I don't understand (probably took it from a tutorial or something).

Hoping you can help me understand the code:

float airPotency =  (-1) * airControl + 1;

fwd = (Last.x * airPotency) + (fwd * _airControl);
sdw = (last.y * airPotency) + (sdw * _airControl);

                
Vector3 forwardVec = (lastForward * airPotency) + (transform.forward * _airControl);
Vector3 rightVec = (lastRight * airPotency) + (transform.right * _airControl);

So I don't really understand what the airPotency function does in the first place so understanding that will probably let me understand the rest.

This block of code controls how much movement control I have in air. I wanted to implement dodging but I think this messes up my dodge while in air.

Thanks for any help!

Advertisement

I would guess that airPotency is supposed to represent some sort of control ‘stickiness’ (since it is equal to 1 - airControl). It would help though if we could see what is done with fwd and sdw (and in fact what Last actually is)

@RulerOfNothing Last is the last saved fwd and sdw. Getting stored right when we leave the ground.

Like RulerOfNothing says, it looks like a number of

// ac = airControl
value = lastValue * (1 - ac) + newValue * ac

equations, except the code fragment doesn't show the connection between ‘lastValue’, ‘newValue', and ‘value’.

It makes a weighted mix of old and new. If ac == 0, it becomes value = lastValue, if ac == 1, it becomes value = newValue, when it's ¾, you get value = ¼ * lastValue + ¾ * newValue

@Alberth oh okay, that makes a lot of sense then. Thank you so much

This topic is closed to new replies.

Advertisement