Hello!
I've created a small function, and I don't know, it works properly or not.
Is this the right code?
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
return Vector(x1-x2, y1-y2, z1-z2).Length();
}
Nope. You can't get the length of a class/instance.
And the length function is: len() and not Length()
Still then, I can't know what you're talking about.
:edit: This code might help you:-
function IsPlayerInRangeOfPoint(v1, v2, range) // by Rusty_Bullet22
{
v1.x -= v2.x, v1.y -= v2.y, v1.z -= v2.z;
return ((v1.x * v1.x) + (v1.y * v1.y) + (v1.z * v1.z)) < (range * range);
/*
Returns true if the player is within a range of 1500 from (0,0,0)
false if not
IsPlayerInRangeOfPoint( player.Pos, Vector( 0, 0, 0 ), 1500 );
*/
}
I haven't made it,
@Cutton did.
My function works properly.
Class Vector has a method, called "Length()"
Quote from: KAKAN on Feb 13, 2016, 01:06 PMNope. You can't get the length of a class/instance.
And the length function is: len() and not Length()
Still then, I can't know what you're talking about.
He's not talking about the container element count /length such as array/table/string. He's talking about the the distance between two points in 3 dimensional space (http://freespace.virgin.net/hugo.elias/routines/r_dist.htm). And the method he's calling is on the Vector instance (https://bitbucket.org/stormeus/0.4-squirrel/src/dfdf3960226db784d7e807770ca3b1b46f51b16c/UtilStructs.cpp?at=master&fileviewer=file-view-default#UtilStructs.cpp-326).
Quote from: KAKAN on Feb 13, 2016, 01:06 PMNope. You can't get the length of a class/instance.
And the length function is: len() and not Length()
Still then, I can't know what you're talking about.
:edit: This code might help you:-
function IsPlayerInRangeOfPoint(v1, v2, range) // by Rusty_Bullet22
{
v1.x -= v2.x, v1.y -= v2.y, v1.z -= v2.z;
return ((v1.x * v1.x) + (v1.y * v1.y) + (v1.z * v1.z)) < (range * range);
/*
Returns true if the player is within a range of 1500 from (0,0,0)
false if not
IsPlayerInRangeOfPoint( player.Pos, Vector( 0, 0, 0 ), 1500 );
*/
}
I haven't made it, @Cutton did.
You are wrong. Vector has the "Length" method.
Quote from: TheMallard on Feb 13, 2016, 01:04 PMHello!
I've created a small function, and I don't know, it works properly or not.
Is this the right code?
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
return Vector(x1-x2, y1-y2, z1-z2).Length();
}
Why did you actually create the code,
It could have been Found (http://wiki.vcmp.org/wiki/Scripting/Squirrel/Functions/DistanceFromPoint) over here, than why make functions, I'm just curious to know why?
Quote from: [TBS]Destroyer on Feb 13, 2016, 07:29 PMQuote from: TheMallard on Feb 13, 2016, 01:04 PMHello!
I've created a small function, and I don't know, it works properly or not.
Is this the right code?
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
return Vector(x1-x2, y1-y2, z1-z2).Length();
}
Why did you actually create the code,
It could have been Found (http://wiki.vcmp.org/wiki/Scripting/Squirrel/Functions/DistanceFromPoint) over here, than why make functions, I'm just curious to know why?
Maybe he don't know there is such function. I don't know too.
Quote from: ysc3839 on Feb 13, 2016, 08:39 PMQuote from: [TBS]Destroyer on Feb 13, 2016, 07:29 PMQuote from: TheMallard on Feb 13, 2016, 01:04 PMHello!
I've created a small function, and I don't know, it works properly or not.
Is this the right code?
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
return Vector(x1-x2, y1-y2, z1-z2).Length();
}
Why did you actually create the code,
It could have been Found (http://wiki.vcmp.org/wiki/Scripting/Squirrel/Functions/DistanceFromPoint) over here, than why make functions, I'm just curious to know why?
Maybe he don't know there is such function. I don't know too.
Okay, well that's not really a serious problem/issue thou.
You can use Vector.Distance( Vector) to get the distance in 3d.
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
return Vector(x, y, z).Distance( Vector( x2, y2, z2 ) );
}