Skip to content

Instantly share code, notes, and snippets.

@RainerHilmer
Created June 8, 2013 17:25
Show Gist options
  • Save RainerHilmer/5735941 to your computer and use it in GitHub Desktop.
Save RainerHilmer/5735941 to your computer and use it in GitHub Desktop.
Replacements for the DistanceTo and DistanceTo2D methods of the ScriptHookDotNet for GTA IV. Reason: the original ones produce unreliable results!
using System;
using GTA;
namespace Cyron43.GTAIV
{
public static class Extensions
{
/// <summary>
/// I know there's a DistanceTo2D in the scripthook but it delivers unreliable results!
/// </summary>
public static float NewDistanceTo2D(this Vector3 vectorOne, Vector3 vectorTwo)
{
var xLength = Math.Abs(vectorOne.X - vectorTwo.X);
var yLength = Math.Abs(vectorOne.Y - vectorTwo.Y);
return (float)Math.Sqrt((xLength * xLength) + (yLength * yLength));
}
/// <summary>
/// I know there's a DistanceTo in the scripthook but it delivers unreliable results!
/// </summary>
public static float NewDistanceTo(this Vector3 vectorOne, Vector3 vectorTwo)
{
var xLength = Math.Abs(vectorOne.X - vectorTwo.X);
var yLength = Math.Abs(vectorOne.Y - vectorTwo.Y);
var zLength = Math.Abs(vectorOne.Z - vectorTwo.Z);
return (float)Math.Pow((xLength * xLength) + (yLength * yLength) + (zLength * zLength), 1.0 / 3.0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment