billiard cue
#1

Hi,

I have billiard cue and billiard ball, how to calculate billiard cue position, to billiard ball?
Reply
#2

Reply
#3

Код:
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.
Reply
#4

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.
Reply
#5

Код:
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
Reply
#6

PHP код:
stock GetDistanceFloat:x1Float:y1Float:z1Float:x2Float:y2Float:z2 )
{
    return 
floatroundfloatsqroot( ( ( x1 x2 ) * ( x1 x2 ) ) + ( ( y1 y2 ) * ( y1 y2 ) ) + ( ( z1 z2 ) * ( z1 z2 ) ) ) ) );

»
PHP код:
Float:GetDistanceBetween2Points(Float:x1Float:y1Float:z1Float:x2Float:y2Float:z2)
{
    return 
VectorSize(x1-x2y1-y2z1-z2);

Reply
#7

Код:
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)