2
$\begingroup$

I have had some trouble locating an example online as to what I am trying to achieve; I am not the greatest at math so I will explain the issue the best I can.

Usage: I have a camera in world space that orbits a target on all axes. The issue this is focused on is moving the camera closer or further away from the target. Now, I have a basic method that works really well for the basic problem. However, the issue I have now is that the camera zooms at a constant rate no matter how close it is to the target (it should zoom slower the closer it gets).

Delta: The variable delta is a value between -120 and 120; this is supplied from the scroll wheel of the user's mouse.

Speed: The variable speed is the reason I am here. I can set this to a value of 3 and zooming is nice and smooth at a constant rate. If I set this to a value of 1000 then the zooming becomes incredibly slow, but remains smooth. This is the desired effect but it needs to be adjusted based on the distance between the camera and the target.

The distance between the camera and the target is essentially the opposite of the speed variable. Meaning, when the camera is further away, the distance is obviously larger; when the camera is closer, the distance is obviously smaller. This creates an issue where if I just use the distance then the zooming gets slower as I zoom out, and as I zoom in it gets faster.

The Question: How do I take a range such as 3 - 1000 and reverse it to where it becomes 1000 - 3?

Note: As I stated previously, I am not the greatest at math so I don't know a lot of the correct terminology and this question is probably not the greatest, but I am trying to be as thorough as possible to assist in the process. Also, if the tag is not correct, please feel free to adjust it.

$\endgroup$

1 Answer 1

1
$\begingroup$

I have solved the mathematics behind it with the help of a friend; I was informed that the solution is exponential decay.

enter image description here

The math behind the solution is (I may need help with the formatting of the exponential function):

$$\mathbf{s = 1000 - \frac{997}{1 + f(d) = -10 \cdot \frac{d - 100}{r - 100}}}$$

Where s is the desired speed, d is the distance from the target, and r is the radius of my target.

$\endgroup$

You must log in to answer this question.

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