billiard cue -
MerryDeer - 19.10.2016
Hi,
I have billiard cue and billiard ball, how to calculate billiard cue position, to billiard ball?
Re: billiard cue -
PrO.GameR - 19.10.2016
Re: billiard cue -
TakeiT - 19.10.2016
Код:
stock GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 )
{
return floatround( floatsqroot( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) + ( ( z1 - z2 ) * ( z1 - z2 ) ) ) ) );
}
X,Y,Z2 will be your ball, X, Y, Z1 is your cue. You may have to use an offset (Like Y+1) to get the proper value for the top of the cue.
EDIT: If you are looking for the direction of the ball, you can use
Код:
GetXYInFrontOfObject(objectid, &Float:x, &Float:y, Float:distance) //function by TakeiT
{
//This function is modified from GetXYInFrontOfPlayer
new Float:a, Float:rx, Float:ry;
GetObjectPos(objectid, x, y, a);
GeObjectRot(objectid,rx, ry, a);
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
}
Simply use it like this:
Код:
new Float:X, Float:Y, Float:Z;
GetObjectPos(ballobject, X, Y, Z); //this is for the Z angle, the X and Y are about to be re written
GetXYInFrontOfObject(cueobject, X, Y, 1.0); //change 1.0 to the you want the ball to go.
MoveObject(ballobject.....);
That's untested, but should work.
Re: billiard cue -
MerryDeer - 19.10.2016
Hm now i use getxyinfrontofobject, like getxyinfrontofplayer, but using object coordinates, all is ok. But billiard cue not in same angle as ball it's some angle out.. I have to add +3 angle to pool cue to make same line, but i want that i don't need to add angle, just calculate that coordinates that biiliard cue and ball make nice stright line to hit.
Re: billiard cue -
TakeiT - 19.10.2016
Код:
GetXYInFrontOfObject(objectid, &Float:x, &Float:y, Float:distance) //function by TakeiT
{
//This function is modified from GetXYInFrontOfPlayer
new Float:a, Float:rx, Float:ry;
GetObjectPos(objectid, x, y, a);
GeObjectRot(objectid,rx, ry, a+3);
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
}
Simply add +3 in the GetObjectRot
Re: billiard cue -
Dayrion - 20.10.2016
PHP код:
stock GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 )
{
return floatround( floatsqroot( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) + ( ( z1 - z2 ) * ( z1 - z2 ) ) ) ) );
}
»
PHP код:
Float:GetDistanceBetween2Points(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
return VectorSize(x1-x2, y1-y2, z1-z2);
}
Re: billiard cue -
MerryDeer - 20.10.2016
Код:
GetXYInFrontOfObject(objectid, &Float:x, &Float:y, Float:distance) //function by TakeiT
{
//This function is modified from GetXYInFrontOfPlayer
new Float:a, Float:rx, Float:ry;
GetObjectPos(objectid, x, y, a);
GeObjectRot(objectid,rx, ry, a+3);
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
}
Yes but i don't want add angle... I want to do same effect with coordinates, because when you have angle of billiard cue not nice to look at it