Inverted distance between objects

Hi,

My math is not at strong level, so I need some help haha.

I am trying to get a value of 0 to 1.0 depending how far the center of my sphere is from the object.
If the object is, for example, 2m (I want this to be an exposed variable) from the centre of the sphere then returns 1.0. as it gets to the end of the sphere it returns 0.

The set up I have now is calculating the distance between these 2 things, but I don’t have control of how far from the centre the object is and the values returns 0 in the centre and 1.0 for the edges.

The collision sphere is attached to the player and the other object is just a static object in the scene.

1 Like

It’s just 1 - ( ‘current distance’ / ‘total distance’ )

:slight_smile:

I am having trouble to calculate the total distance of my sphere.

Also I am a bit confused with your answer, sorry.

This is what I currently have:
Current setup posted by anonymous | blueprintUE | PasteBin For Unreal Engine

It’s a bit overkill, maybe.

If I want to know the normalized distance from my blueprint to an actor:

Then to calculate

distance

closeup

And if you want it to be 1 by the time it gets to the cube, it’s just 1 - this.

Thank you, It makes more sense now!

I am still a bit confused in the “1 - this” what do you mean by that?

Edit: Nevermind, got it! Thank you

1 Like

:+1: :smiley:

@ClockworkOcean
How can I calculate the penetration of the object into the sphere?

We have calculated the distance to the pivot point here. Which is the center of the default sphere.

In general, you can’t calculate how much penetration you have, because it depends on the shapes.

Can I not somehow calculate it by using the radius of the sphere? So based on how much I have entered the radius make it 0 or 1.0.

I might be talking nonsense here lol

You could try, but what happens when it’s the flat side of a cube, and then the pointy bit of a cube?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.