I need a variable to increase when two objects get closer together.
health -= health * decreaseRate;
I need the decreaseRate to increase the closer the player is to an object. How would I go about doing this, mathematically?
I need a variable to increase when two objects get closer together.
health -= health * decreaseRate;
I need the decreaseRate to increase the closer the player is to an object. How would I go about doing this, mathematically?
(some constant) / (distance) is one option.
e.g.
5 / 1 = 5
5 / 5 = 1
5 / 10 = 1/2
But then the number gets smaller, not bigger.
5 / (distance)
5 / 1 = 5
5 / 5 = 1
5 / 10 = 0.5
I need the number to get bigger, not smaller
Take a look at the numbers again - the result is bigger the closer you are.
Oh right, I feel stupid now
Thanks heaps
im sorry but i dont understand a thing can you use it in a script please
float currentDistance = Vector3.Distance(transform.position, targetObj.position);
GetComponent<AudioSource>().PlayOneShot(audioClip);
GetComponent<AudioSource>().pitch = 10/currentDistance;
I hope this helps ![]()