Merge pull request #27452 from Chaosus/direction_to

Added method to retrieve a direction vector from one point to another
This commit is contained in:
Rémi Verschelde 2019-04-08 12:00:54 +02:00 committed by GitHub
commit 7f3373d79f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 0 deletions

View file

@ -132,6 +132,11 @@ namespace Godot
(-p0 + 3.0f * p1 - 3.0f * p2 + p3) * t3);
}
public Vector2 DirectionTo(Vector2 b)
{
return new Vector2(b.x - x, b.y - y).Normalized();
}
public real_t DistanceSquaredTo(Vector2 to)
{
return (x - to.x) * (x - to.x) + (y - to.y) * (y - to.y);

View file

@ -126,6 +126,11 @@ namespace Godot
);
}
public Vector3 DirectionTo(Vector3 b)
{
return new Vector3(b.x - x, b.y - y, b.z - z).Normalized();
}
public real_t DistanceSquaredTo(Vector3 b)
{
return (b - this).LengthSquared();