- Home /
Distance to object I am looking towards
My game is a First Person Shooter.
Mech-Collider was too inaccurate for my taste, so I thought of having a certain code as well as the collider code.
I want to be able to determine the distance from the point I launch the missiles to where they will most likely hit, and then I will use this distance for determining when the missile should blow up if aimed at a wall or the ground.
How would I determine this distance?
Answer by Steffen Franz · Jan 31, 2011 at 07:32 PM
construct a vector between the two points you want to measure, then get the magnitude of the vector.
float distance = (endPoint - startPoint).magnitude;
even better to use Vector3.sqrmagnitude -> " Returns the squared length of this vector (Read Only). Calculating the squared magnitude instead of the magnitude is much faster. Often if you are comparing magnitudes of two vectors you can just compare their squared magnitudes. "
Your answer
Follow this Question
Related Questions
Colliders not interacting 0 Answers
How to do a frontal-only shield of sorts? 1 Answer
Drawing a line in front of player weapon 0 Answers
Different types of projectiles cause different amounts of damage... 1 Answer
Internal collisions 1 Answer