-
Notifications
You must be signed in to change notification settings - Fork 450
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
Improvements to FlxCamera#followLerp #1220
Conversation
The elapsed's get cancelled in the numerator and denominator anyway. Probably doesn't jitter when followLerp = 0, but I didn't check for it.
Is this supposed to fix some issue or simply code cleanup? If the latter is the case, it should proudce the same results, which it doesn't. I think it's pretty important for |
The issue is that |
Is there a demo we can check to make sure this doesn't break anything? It seems like a good fix. |
We have to verfiy that the Either way, I don't think we can simply leave the elapsed time out of the equation, all movement in flixel has to take it into account. |
I think Do you want a unit test, or like the FlxCamera demo using both ways? |
You could have a moving camera target without any If this fixes the camera jittering mentioned in that comment, that fix should probably be removed? |
I can't tell with certainty that the jittering is gone. It -might- be gone, but I don't notice it either way. Could @JoeCreates upload the source to the final Zilla test from #797? Directly setting the position is iffy. Without lerp, the 30 fps version takes 1/30 seconds to move, and the 60 fps version takes half as long. Same thing if I said |
This math was definitely wrong. The Specifying it in terms of seconds might be a bit tricky, though, seeing as the follow speeds change so quickly. That's not to say it couldn't be made consistent with respect to FPS, though, which would look something like:
(Which would make the follow speed consistently what it used to be on 60FPS games.) People would have to convert their lerp values if they weren't using 60fps, though, and that wouldn't be so easy. On a side note, is it just me, or would it be easier to use a ratio (from 0 to 1) for lerp? Currently the value for lerp means something like "1 / ratio + 1", or "move a (lerp plus 1)th toward the target each frame". As such, I've always tended to pick a lerp value entirely on trial and error. :P |
@JoeCreates This definitely needs to be fixed, and I think most people use 60 fps to begin with. We just have to make sure to mention this in the Changelog / upgrade guide. A range from 0 to 1 does make more sense to me. I think @prog4mr originally implemented this, any thoughts? |
@JoeCreates 0 lerp makes sense, but what does I think it would be |
@MSGhero Either that or it could be the other way round, i.e. You're right about the *60, by the way. Elapsed is roughly 1/60 at 60fps so it needs to be multiplied by 60 again to normalize, not divided as I had done. |
@JoeCreates so would the end result be If so, the existing jitter fix probably needs to stay. |
Unsure about jittering right now
The jitter fix no longer works since I had to add |
By manually fixing the FlxG.random calls, you created a merge conflict - you need to pull from the current dev branch and fix those. |
I'll get this right one day
Updating to recent dev
Not sure if jittering will be an issue again. Only place I could find |
Checked in the original zilla demo, and visually it looks the exact same as it did with the jitter fix. There's always a bit of bitmap tearing in flash, but ignoring that, camera movement was smooth. Nothing like the original swf he uploaded. |
@@ -1096,6 +1090,14 @@ class FlxCamera extends FlxBasic | |||
return _point.set(flashSprite.scaleX, flashSprite.scaleY); | |||
} | |||
|
|||
private function set_followLerp(Value:Float):Float | |||
{ | |||
if (Value < 0) Value = 0; // lerp is bounded between 0 and 1 inclusive |
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.
We have FlxMath.bound()
for this. :)
return followLerp = FlxMath.bound(Value, 0, 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.
Oh, of course there is.
@MSGhero The jitter fix on |
@@ -62,8 +61,10 @@ class FlxCamera extends FlxBasic | |||
public var targetOffset(default, null):FlxPoint; | |||
/** | |||
* Used to smoothly track the camera as it follows. | |||
* Valid values between 0.0 and 1.0. | |||
* A value of 1 means no camera easing. A value of 0 means the camera does not move. |
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.
Hm, "easing"... Makes me wonder, would it be useful to allow using FlxEase
functions for followLerp?
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.
That's interesting. How would that be handled if the camera is following a moving player? Seems like the ease parameter would get reset each time.
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.
The AS3 library TweenLite has a "throwProps" plugin for when something is being altered each frame while being tweened, But it's proprietary, not on github :(
Issue:
|
@MSGhero That is a bit of an issue . . . It would also mean that we shouldn't cap the lerp at 1, seeing as the framerate might be higher than 60. The fix would have to be applied with the condition |
I'll see what Gama says, it's starting to look a bit messy. It's a bit like we're manually tweening the camera but without being given a duration. The original lerp basically said "the camera will take followLerp extra frames to reach its destination." What is it trying to say now? |
@MSGhero Actually, that's not what the original said. Remember that every frame the distance moved toward the target decreases. For example, if the original Now what lerp would be saying is "move followLerp of the way toward target each 60th of a second". |
That's the plan, anyway.
Added those changes. The FlxCamera demo doesn't do the lerp justice anymore since 1 -> .9 is much less drastic than .2 -> .1 or even .1 -> 0. |
Hm... it seems very strange to me that the range of values for |
@Gama11 Perhaps it's just better to leave it framerate dependent, then? :P It's not that tricky for people to account for framerate differences themselves. If we could come up with a more flexible solution with easing it might be a bit better, but that seems pretty tricky, too. |
Improvements to FlxCamera#followLerp
Hm... I've merged this for now, but it just occured to me that the max possible value on the update fps might be able to lead to some very confusing behaviour when the user changes the fps at runtime, after the creation of the camera where the followLerp values is determined.. Might wanna revisit this later. |
I have previously done the math behind this very case: Lerp with variable time step. TLDR: The mathematical correct solution for your kind of lerp with variable timestep is: Where does the (1/60) come from? For details see: https://xaedes.github.io/tech-gain-filter.html#h2_applications |
The elapsed's get cancelled in the numerator and denominator anyway. Probably doesn't jitter anymore when followLerp = 0, but I didn't check for it.