4
\$\begingroup\$

I'm having trouble coming up with a formula/method of creating third person camera with a variable distance from the player given a specific camera pitch.

This image shows something close to my desired result:

Camera Distance from Pivot and Aim Offsets

I basically only have two requirements. The camera has to be directly calculated from a pitch. The camera should roughly follow a smooth curve between the minimum and maximum camera distance and the halfway point is around 50% of the distance (as seen by the graph in the top right of the image).

So, Option A:

I create a function online to convert a pitch directly to a camera distance and use that. http://www.timotheegroleau.com/Flash/experiments/easing_function_generator.htm

I have this working and it ends up looking close but has two distinct problems. It is rigid and doesn't allow me to edit any of the offsets or distances without having to create a whole new function and the camera at 0 degrees pitch ends up being around 15-30% of the maximum distance which doesn't feel as good as if it were closer to 50%.

Option B:

Come up with a spline, perhaps a cubic bezier, between the min and max distances and somehow project the camera on to that spline given a specific pitch. I'm not sure how I would be able to do this. The disadvantages would be that the camera distance curve would not be as smooth without some tweaking and again it would require more work if any of the distances or offsets change.

Option C:

Come up with a specific formula which I have no idea how to find. Given the min and max camera distances, the offsets, and the camera pitch, return a distance that follows a smooth camera distance curve and a mid point of roughly 50% of the max distance.

So my question is can/how do I accomplish Option B or C? Is there a better way?

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Related: 50 Game Camera Mistakes \$\endgroup\$
    – Theraot
    Feb 18, 2017 at 5:50
  • \$\begingroup\$ That's the video that gave me the idea, unfortunately he doesn't go into technical detail. The slide is at 20:31 for those wondering. \$\endgroup\$
    – Saevax
    Feb 18, 2017 at 14:13

2 Answers 2

1
+100
\$\begingroup\$

I would look into using an AnimationCurve for this. Add a curve to the script that controls your camera, then use the inspector to plot camera distance vs. pitch angle. (If the pitch has to go negative, I believe you'll have to offset it. No big deal!)

Now you can evaluate this curve (passing in pitch + offset) to get your camera distance out.

This will be quick to edit, and you should be able to fine-tune the curve while the game is running.

\$\endgroup\$
2
  • \$\begingroup\$ I looked into it and it seems like a viable solution but is finicky. Because of how the camera is offset (AimOffset - Vector3.forwad * distance) a straight forward equation with just 2-3 control points isn't enough to have a smooth camera path. imgur.com/a/6eyzP It's definitely more effective, and faster, than playing with a quintic bezier curve though. \$\endgroup\$
    – Saevax
    Feb 24, 2017 at 0:22
  • \$\begingroup\$ I think you're right, the strength of this approach is that it's simple to implement and quick to iterate on. I do think that you can get a great result with it, but you might have to use more than a couple of control points and it'll definitely take a lot of tweaking. \$\endgroup\$
    – Victor T.
    Feb 28, 2017 at 22:10
0
\$\begingroup\$

To make sure that I understand, what you're saying is that for option A: when you have the camera "flat" (pitch 0) it feels like it's too close to the player? If so... welcome to every third person game ever!

In all seriousness though, I think that you're maybe overthinking it. Why not take option A and then put a check in place for under/over certain pitch values and modify the distance slightly? What you'd essentially get is the typical 3rd person "bounce" when you go too high or low with the pitch.

I would also say that in the end most players prefer to manually set and adjust the camera distance themselves, making the auto-distance floating camera kind of a moot point. Obviously it needs to be functional, but I wouldn't worry about it being absolutely perfect because a lot of people won't use it.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .