For a game I'm making I'm trying to design a button that is repelled by the cursor like a magnet while being tethered to a virtual spring. The tether point is the center of the button (imagine a basic square). The force of this tether (or the force of the magnetic effect, depends on how you want to see it) defines how hard it feels to click the button. I've called this parameter power. For this function I've decided to simplify the entire square to a single point, which is again the tether. Now that I've explained the context, let's get into the math. I've figured out how to move this button in the opposite direction of the cursor-to-tether line so the only thing I'm calculating is the strength with which this happens (basically, how far away to move it in that direction). That's the result of the function I'm trying to create.
The simple, initial approach I used was this function: [MATH]moveAmount = \frac{1}{\sqrt{mouseDistance}}[/MATH]. This function moves the object relatively further away as the cursor gets closer to the tether point. However, this does not take into effect the spring effect. Right now, you could in theory move the object into infinity if computers would be precise enough. I want to add a spring effect that pulls the object back to the tether point as it gets pushed further away. That could look like this: [MATH]springPull = moveAmount^2[/MATH]. Now, as moveAmount approaches infinity, springPull will also approach infinity at a quadratic rate. However, I need to combine this function with the first one, because springPull should limit the total distance the object should be moved with.
My first question is how, in general, this effect of one function limiting the other can be achieved. My second question is how to add these two functions together without creating a circular dependency. How can you calculate moveAmount if the value of moveAmount itself is required for calculating the result?
Keep in mind that things can be simplified and don't need to be as physically accurate as possible. In the end, it just needs to feel good to the user. I would love a detailed explanation though about the most accurate way, so I can do the simplification myself. I want to understand this. For reference, I've passed calculus in uni but I was never very good at it. That was also over two years ago and I haven't used it much since. I have however not passed linear algebra.
I'm not entirely sure in which category of algebra this fits; it might be moving into calculus areas but at the same time I feel like this should be so simple.
The simple, initial approach I used was this function: [MATH]moveAmount = \frac{1}{\sqrt{mouseDistance}}[/MATH]. This function moves the object relatively further away as the cursor gets closer to the tether point. However, this does not take into effect the spring effect. Right now, you could in theory move the object into infinity if computers would be precise enough. I want to add a spring effect that pulls the object back to the tether point as it gets pushed further away. That could look like this: [MATH]springPull = moveAmount^2[/MATH]. Now, as moveAmount approaches infinity, springPull will also approach infinity at a quadratic rate. However, I need to combine this function with the first one, because springPull should limit the total distance the object should be moved with.
My first question is how, in general, this effect of one function limiting the other can be achieved. My second question is how to add these two functions together without creating a circular dependency. How can you calculate moveAmount if the value of moveAmount itself is required for calculating the result?
Keep in mind that things can be simplified and don't need to be as physically accurate as possible. In the end, it just needs to feel good to the user. I would love a detailed explanation though about the most accurate way, so I can do the simplification myself. I want to understand this. For reference, I've passed calculus in uni but I was never very good at it. That was also over two years ago and I haven't used it much since. I have however not passed linear algebra.
I'm not entirely sure in which category of algebra this fits; it might be moving into calculus areas but at the same time I feel like this should be so simple.