3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1] 2

Author Topic: Example to demonstrate Pool Cue and Ball Interaction  (Read 1345 times)

« on: May 13, 2012, 02:14:55 AM »
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




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 ! 8)

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
AKA: The 3D Raddict http://www.3draddict.com/
« Reply #1 on: May 13, 2012, 02:47:36 AM »
thx allan but i tried extracting the rar file and error is cant find physx
« Reply #2 on: May 13, 2012, 03:28:33 AM »
just made a donation and i cant even find link to new version. god im having mountains of problems and feel like im being a pain in the ass now. ca1n u just explain to me all the settings u have to this scenario? i swear this is driving me mad.
« Reply #3 on: May 13, 2012, 04:20:07 AM »
I'm afraid any explanation I give will cloud things even further for you, without this project to refer to  ???

Please could one of the moderators investigate why Ricky is unable to download 7.22, after having made his donation?

Ricky, what version of 3DRAD are you currently using, and please supply some info on your PC make, graphic card and operating system.
« Last Edit: May 13, 2012, 05:33:16 AM by AllanF »
AKA: The 3D Raddict http://www.3draddict.com/
« Reply #4 on: May 13, 2012, 04:42:15 AM »
its juat a laptop with large external monitor. xp , acer travel mate. yesw u think u could quickly tell me whats linked to what here and any other settings i need? have u go the cue pivoting then shooting?
« Reply #5 on: May 13, 2012, 05:45:05 AM »
Well, maybe one of the tech fundis on this forum will be able to tell you if your system is adequate and what else you need to install?

I really have not the time to get more involved in this, but here are all the links for the various objects used in the project. As I said previously, it is now over to you.










AKA: The 3D Raddict http://www.3draddict.com/
« Reply #6 on: May 13, 2012, 08:06:10 AM »
anyone else help me then? im really starting to feel lonely around here. could someone plz try that demo and tell me if it works then i will know if its my end or not. just donates some money for new version and now link is empty page.  ???. i really am having a hard time here.

psikoT

« Reply #7 on: May 13, 2012, 09:47:34 AM »
stop crying please... you've received a lot of help from some masters here... I told you, in your first post about your obsessive idea, that you simply need to familiarize with the engine before start to making a specific game like this, but looks like you don't want to understand...  I'm using this engine since 3/4 years ago and still see this kind of project a bit 'special'... simple, but special... something which requires a big scripting knowledge and imagination... and you are unable even to compile a game...

explore 3drad first, man... make a fucking racing game, or a FPS, or whatever (except a GTA clone ;D)... learn how the engine works with simple things, then try to make a pool game... that's my advice...

PS.- thanks Allan, I will use it for my pool game ;D ;D ;D
« Reply #8 on: May 13, 2012, 09:56:02 AM »
explore 3drad first, man... make a fucking racing game, or a FPS...

What, you say making a FPS is easy?  ::)

 ;D
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0

psikoT

« Reply #9 on: May 13, 2012, 10:03:03 AM »
at least there are a lot of examples and resources to start up... ::)

but yes, FPS are easy :P

psikoT

« Reply #10 on: May 13, 2012, 10:15:05 AM »
[offtopic]

here's my story: in 2008 I wanted to make a TPS game, I tried with 3drad and I was unable to make a decent setup for the character... I leave that idea and start to making a racing game. I spent 2 years learning 3drad to make the fucking racing game and voil�... once I've done a racing game (not finished but almost) I can magically setup a character in 3drad... how is that?  a racing game has nothing to do with a TPS game... but that gaves me the necessary knowledge... that's the point.

[/offtopic]
« Reply #11 on: May 13, 2012, 05:56:35 PM »
sry guys, was getting frustrated yesterday.
got demo working and it has given me somthing to work with. its going to need a lot of tweaking to get it to do what i want. so i think im going to study that script and try to understand what all the coding means. the first thing i will want to know it how to get cue to go thru in a str8 line. i had it coming thru perfectly str8 with the paddle script but i could not rotate cue. maybe i need that script in there too. but i am afraid to ask anymore . lol. anyway thanks very much, youve given me a start.
« Reply #12 on: May 14, 2012, 02:07:20 AM »
i am so pleased with myself. from your demo i changed the pivot point of cue. u done a great job but i realised it has to pivot from the dead centre of cueball. so i moved the pivotball right above cueball. this is what i needed to get started.. thyanks very much allan. ;D
« Reply #13 on: May 14, 2012, 02:26:12 AM »
Thanks, Ricky.

I'm glad that you are making some progress, and experimenting with the demo. ;D
AKA: The 3D Raddict http://www.3draddict.com/
« Reply #14 on: May 14, 2012, 02:40:23 AM »
thanks allan, im under jestermon's wing now so watch out. haha. im thinking my next step is to have that cam follow but of cue so im always looking down shaft of cue. im not hinting for help here.. u have done enough for me for now. (for now)  :P
Pages: [1] 2