Jump to content

code in range


javad_iran

Recommended Posts

public static bool IsInRangeOfPoint(Vector3 playerPos, Vector3 target, float range)
    {
        var direct = new Vector3(target.X - playerPos.X, target.Y - playerPos.Y, target.Z - playerPos.Z);
        var len = direct.X * direct.X + direct.Y * direct.Y + direct.Z * direct.Z;
        return range * range > len;
    }

Example of usage:

if(IsInRangeOfPoint(player.position, new Vector3(0, 0, 0), 5f))
{
	// the player is close to the coordinates >> (0, 0, 0)
}
else
{
	// the player is not close to the coordinates.
}

 

 

Link to comment
Share on other sites

14 hours ago, skazi said:

public static bool IsInRangeOfPoint(Vector3 playerPos, Vector3 target, float range)
    {
        var direct = new Vector3(target.X - playerPos.X, target.Y - playerPos.Y, target.Z - playerPos.Z);
        var len = direct.X * direct.X + direct.Y * direct.Y + direct.Z * direct.Z;
        return range * range > len;
    }

Example of usage:


if(IsInRangeOfPoint(player.position, new Vector3(0, 0, 0), 5f))
{
	// the player is close to the coordinates >> (0, 0, 0)
}
else
{
	// the player is not close to the coordinates.
}

 

 

thanks.

how to get time for your cmd?

example:

if(IsInRangeOfPoint(player.position, new Vector3(0, 0, 0), 5f))
{
	console.log(`${player.name} use the cmd in ${time} `);
}

for ${time} please help

sorry for bad english

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...