Answers for "Speed based on distance"
http://answers.unity.com/questions/1785688/speed-based-on-distance-1.html
The latest answers for the question "Speed based on distance"Answer by unity_ek98vnTRplGj8Q
http://answers.unity.com/answers/1785732/view.html
Your first issue is that you don't just want the distance, you also want the direction to your object so you know what direction to move in. Luckily, this is exactly what a Vector is, it is a mathematical structure that contains both *Direction* and *Magnitude*. So lets start by grabbing the Vector between your object and your target. This can be done by subtraction your object's position from your targets position.
Vector3 toTarget = target.position - obj.position
Now lets lets multiply by a speed factor. This will let you control how fast you want to go based off of how far away you are.
float speedFactor = 2;
toTarget *= speedFactor;
Now you have a vector that represents both the direction you want to travel AND how fast you want to travel, based off of your distance to your target. Now you just need to set your velocity (No need for Time.deltaTime as Velocity is independent of framerate
rb.velocity = toTarget;Tue, 03 Nov 2020 19:21:59 GMTunity_ek98vnTRplGj8Q