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
Implement very basic look ahead functionality #284
base: main
Are you sure you want to change the base?
Conversation
I definitely see what you mean. What would make the most sense to me when trying to replicate the camera in question, would be framed follow mode, with the look ahead for it acting to offset the frame as well (and, therefore, give the player some leeway before shifting the camera the other way). Hollow Knight does something similar for the X axis, just without dead zones: Technically, Hollow Knight's camera's X axis behavior could be replicated by allowing the offset to persist, setting the As for the Mario camera, the same could be done, but with framed follow mode and checking if the frame moved instead of the However, I think you point out a good distinction in the sense that there is a difference between Mario and Hollow Knight's directional look ahead, and this PR's velocity based look ahead. The former is more so a "forward focus", and the latter a "velocity offset". Might be a good idea to split the look ahead functionality into these two instead, then, as it'd allow to recreate the Mario camera, but also with an additional offset that scales with velocity when going really fast (for a more momentum-based game). I.e.:
|
This is neat! Please correct me if I misinterpret how the values are being set and applied to the camera position. The challenge I see with defining min / max velocity and min offset values is that those values will, likely, need to change as the target's velocity speeds up or slows down. Whereas if it relies on time, then the velocity will dynamically change the The way I imagine it is that you would have the following properties:
I want to be careful about not overcomplicating the feature and being too opinionated about how it works — particularly for a first iteration. Think this is one of those things that can be done in many ways depending on the needs of a project. Can think of cases where a user would want to enable or disable the About the alternative way of toggling visibility for the |
I've been thinking about this one. It's technically just a I can think of a game where the movement and "looking" are decoupled (one using WASD, the other IJKL, for example). But then there are two options that the developer could want:
This is also why I think naming this functionality "Lookahead" could be a bit misleading, especially for people who have no knowledge of Cinemachine, as opposed to naming this some kind of "Velocity offset". One a side note -- in order to achieve this functionality using As for time vs. min/max velocity, I like the fact that it's effectively decoupled from the follow target's speed. I've gone with min/max velocity initally because it'd be easy to use different interpolation functions (your It'd technically be possible to have a "Lookahead min" and "Lookahead max" offset and use those for the interpolation. That is, calculate the offset depending on where the follow target will be in X seconds, and use that for the interpolation calculation if interpolation isn't set to none. I don't know how interpolation would interact with smoothing/damping in general, though; will have to experiment with that. |
I've gone with "smoothing" instead of "speed" for controlling the offset. There is a
|
There was a similar disucssion on Unity's forum about the Lookahead feature for Cinemachine. From that conversation, there is a seemingly agreed idea of allowing the Lookahead mechanic to not move back towards its targeted position based on a user defined parameter. Though as that was not included in Cinemachine, at least at this point in time, one can argue that it isn't needed for a first iteration for this feature. Just something to keep in mind if nothing else.
Think a solution to that could be a
I think both terms have merits. “Velocity offset” infers that the camera will change position, or be offset, due to changes in velocity. While “Lookahead” infers that the camera is looking further ahead from its current position. To my mind, the main interpretational difference is that “Lookahead” suggests that the camera is explicitly moving forward, whereas “Velocity Offset” implies that it's just being offset without a particular direction in mind. To your point, “Lookahead” in of itself doesn't necessarily tell the user what it will actually do and works more like an interpretive description rather than a technical one — similar to “damping” vs. “smoothing”. Though do think that's an easy solve with documentation or by the user enabling it themselves and trying it out. There is also an inverse risk of renaming something that people who are familiar with the feature in Cinemachine to something else that works the same way.
Not entirely sure how it would impact
Not sure if a
The above was based on some tests in the latest Cinemachine release in Unity 6. It also made me realize that For the smoothing operation itself, instead of the |
Compared to the old look ahead PR (#160), this has the disadvantage of being directly affected by
follow_damping
(though conceptually, I am completely fine with that). Otherwise, it is very reminiscent of the original, being implemented only for the 2DSIMPLE
mode with a follow target (as that is the main use case for me), but the@export
values are much friendlier for me to use personally.Additionally, I've included a potentially better way of defining
@export
property visibilities. This approach has the advantage of less code distance (i.e. being able to define a property's visibility right where you define it), but it also has the disadvantage of needing an editor reload every time you change when it should be visible. I'm also unsure of how it'd interact with otherproperty.usage
values, but they should co-exist peacefully in the_validate_property()
function. Note that this is merely a proposal.Still a few
TODO
s left at the very least; opening a PR to get input on the aforementioned, how to reconcile the 2 PRs together, and nitpicks of course :^).