Download

Blend between 2 floats?

I’m looking for something that kinda sorta resembles a lerp (or maybe a lerp would work but I don’t know what kind of formula I would use to implement it).

I want to get my mouse on screen coordinates (X and a Y) and compare it against my player character. I need to calculate the distance from my mouse to my player but ONLY up to 200 units, then return the relative X and Y.

I have mostly implemented this already, and clamped the floats at 200. So if my mouse is on my player it reads X0-Y0. If I go straight up or straight down then Y will span between -200 and 200 perfectly fine. The same goes for X when moving left and right.

HERE’S THE MEAT OF THE PROBLEM:
If I move far enough up/down AND far enough left/right, then my returned values look something like X200Y200 or X150Y-180 (you get the point). Im wanting a circular radius. Of 200 units, not a 200x200 hitbox. Is there some sort of function (or even a mathematical formula) that can effectively blend between X and Y? Picture a sliding scale that’s either all of X or all of Y. Or maybe it’s 75% X and only 25% Y ect.

At face value this sounds like lerping (or inverse lerping?) would be what I’m looking for, but I’ve only seen it used to scale between two seperate values on a linear scale, I’m not sure if there’s a way to scale between 2 seperate variables that may potentially have the same value. Any advice would be greatly appreciated

Finterpto

Didn’t read your whole post. Just the title…

Or use a timeline for the lerp.
The output variable needs to go from 0 to 1 over the amount of time you need.

Remember your Pythagoean theorem.

Try the Distance 2D node, u can clamp and remap the result to whatever range u would like

1 Like

I ended up going this route, didn’t exactly solve what I was wondering about blending between floats (which sounds like it could be a useful tool in the future) but I DID achieve what I needed to do this time. I took my mouse 2d vector and subtracted my player 2d vector. Then I clamped it at 200 and did an inverse lerp with that as the alpha. Worked like a charm