This is in response to the query by ricky54321 in the Technical section. I did post him a quick small project as to how he might go about a solution, but the project was written using 7.22 and he does not have that latest version. The project uses physics, and I've found that the versions prior to 7.22 have been buggy in that respect, so I decided to make a more detailed demo (using 7.22), and dish it out as a compiled version with accompanying script and pics of the Editor setup, so that ricky54321 and others can get a better idea of what's cooking.
Here goes:
Oveview
Slider Joint Location
Property Settings
My advice to folks who want to make serious use of the physics side of 3DRAD is to invest the small amount of $5 to get v7.22 !
I've attached 1) a .zip containing the rigidbody Lego axle I've used as a cue stick (too lazy to build a real one)
2) a project file for those with v7.22
3) a .rar with the compiled project for those without v7.2
Here goes:
Oveview
Slider Joint Location
Property Settings
Code: [Select]
//---------------------------------------------------------------------------------------------------
//Example to demonstrate the use of the mouse to position and orientate a pool cue.
//The pool cue is a rigidbody linked to a moveable pivot (small heavy ball object) slider joint.
//The slider is activated by it's motor Z spin value (see Joint object Property dialog)
//User Controls as follows:
// Mouse drag with LEFT button down = Rotate cue around pivot point
// Mouse drag with RIGHT button down = Move cue in X and Z directions
// UP arrow key = Activate cue to hit cue ball
//---------------------------------------------------------------------------------------------------
//Written by: Allan C Farquharson (AKA "3DRADDICT") 13/05/2012
//
//For use with 3DRAD v7.22
float Ay; //Y rotation angle for cue
Vector3 mouse1; //current mouse position
Vector3 mouse0; //previous mouse position
Vector3 mouseMove;//dist mouse moves at each frame
bool mouseLeftKey = false; //store state of left mouse button
bool mouseMiddleKey = false; //store state of middle mouse button
bool mouseRightKey = false; //store state of right mouse button
bool keyUP = false; //store UP arrow key state
bool keyDOWN = false; //store DOWN arrow key state
void Main()
{
iObjectHide(OBJ_22);
// Store current mouse pos in 'mouse1' vector
mouse1.x = iMouseX()*32.0f-16.0f;
mouse1.y = 12.0f-iMouseY()*24.0f;
mouseMove = mouse1 - mouse0; // mouse move distance
// Store which mouse button clicked
if (iMouseButtonDown(0)) //left button
{
mouseLeftKey = true;
}
if (iMouseButtonDown(1)) //right button
{
mouseRightKey = true;
}
// Reset left mouse button flag
if ((!iMouseButtonDown(0))&&(mouseLeftKey))
{
mouseLeftKey = false;
}
// Reset right mouse button flag
if ((!iMouseButtonDown(1))&&(mouseRightKey))
{
mouseRightKey = false;
}
//apply angular damping to cue ball and target ball so that they don't roll forever
iObjectDampingApply(OBJ_0,0.05,0.05,0.05,true,true);
iObjectDampingApply(OBJ_66,0.05,0.05,0.05,true,true);
if (mouseLeftKey)//rotate cue around pivot points Y axis
{
iObjectDampingApply(OBJ_22,0.05,0.05,0.05,true,true);
Ay+=mouseMove.x * 3;//multiply by a sensitivity factor
Quaternion Q;
iQuaternionFromEulerAngles(Q,0.0,Ay,0.0,"xyz");
iObjectOrientationSet(OBJ_22,Q);
}
if (mouseRightKey)//move cue in X and Z directions
{
iObjectDampingApply(OBJ_22,0.05,1.0,0.05,true,true);
Vector3 L;
iObjectLocation(OBJ_22,L);
L.x+=mouseMove.x;
L.z+=mouseMove.y;
iObjectLocationSet(OBJ_22,L);
}
if ((iKeyDown(iKeyCode("DIK_UP"))) && (!keyUP))//activate cue to hit ball by one click of UP arrow key
{
keyUP = true;
OUT_46 = 15.0; // you can make this variable for weak/strong hits of cue ball
}
if (!iKeyDown(iKeyCode("DIK_UP")))
{
keyUP = false;
OUT_46 = -15.0; // slide cue back when UP arrow key is not pressed
}
//store current mouse position into previous mouse position
mouse0 = mouse1;
}
Nothing too elaborate like camera following.....just the main action of positioning the cue and taking a shot at the ball.My advice to folks who want to make serious use of the physics side of 3DRAD is to invest the small amount of $5 to get v7.22 !
I've attached 1) a .zip containing the rigidbody Lego axle I've used as a cue stick (too lazy to build a real one)
2) a project file for those with v7.22
3) a .rar with the compiled project for those without v7.2