Game Development Community

Help in tge in pushing objects

by Kunalvardhan · in Torque Game Engine · 12/12/2006 (9:15 pm) · 6 replies

Hi friends ,
i am a beginer in tge and trying to make a project for my class assignment in torque. . I am trying to push a obect like rock in tge but dont know how to do it . I would really appreciate it if some one can help me about how to go about it.
thanks
kunal

#1
12/12/2006 (9:40 pm)
I am going to make the assumption that your rock is a static shape. It is to be noted that my coding example is from Torque 1.4.2. There is a method processTick that exists in the StaticShape class. Inside here you could put code for a physics simulation. Here is a brief example of what the method could look like with some added code:

Parent::processTick(move);

   // Image Triggers
   if (move && mDamageState == Enabled) {
      setImageTriggerState(0,move->trigger[0]);
      setImageTriggerState(1,move->trigger[1]);
   }

   //This code here is retreiving the objects x,y,z location. It is located in column 3 of the MatrixF     
   //mRenderObjToWorld. Column 1 and 2 are used for the objects rotation. 

   Point3F pos;
   mRenderObjToWorld.getColumn(3,&pos);
   MatrixF mat = mRenderObjToWorld;

   //After getting the x,y,z position you could modify it creating newX,newY,newZ.
   mat.set(Point3F(newX, newY, newZ);
   
   //You would then place the new information into your matrix.
   mat.setColumn(3, pos);

   //The object is now moves to your new position
   Parent::setTransform(mat);
   Parent::setRenderTransform(mat);

   //---More code here
   }

The above code shows you how to change the location of the object in a forced manor. Having a player act on this object is a different story. One thing you could do is this:

1) Have the player cast a ray forward when the user presses a use key.
2) When you get the object that the ray hit call a method that you write.
3) Inside of this method you could write code to change the objects position.

*make sure you call setRenderTransform and setTransform. You must also make sure that the new location of the object is sent over the network with this statement:

setMaskBits(PositionMask);


Hopefully this will help you. If I have not made anything clear enough please let me know and I will try to make it clearer.
#2
12/12/2006 (10:44 pm)
Hi joshua thanks for such a prompt reply . Me and my collegue are working on the project together. He is the programmer and i am the designer and animator. the problem is he is not available and its n emergency that i nedd to get this done . the code you sent me i really dont understand what to do with it. is there anyway you can be more specific about where and how to use it. i am sorry i am being a pain in ass but i would really appreciate your help
thank
kunal
#3
12/13/2006 (8:48 am)
I am not really sure how I can be much more specific but perhaps this will help. If you look at the processTick method inside of a StaticShape object and compare it to what I wrote then you should be able to see how to force a movement in the object. Knowing this you could follow my instructions to have a player interact with the object. Inside of the method you use to change the objects location you could take the Player interacting with it in as a parameter. You can then take the players eye vector with getRenderEyeTransform(~) and use that to move the rock in the same direction. Hopefully this will help you. If what I have said is still not making sense then this may be out of your league for the time being. The engine is not the easiest thing to jump into and accomplish things even with programming experience.
#4
12/13/2006 (9:03 am)
Today must be move an object day. :D

You might be able to move the rock by using its onCollision callback. So when the player collides with it, move it the direction the player is facing.
#5
12/13/2006 (11:19 am)
I was thinking the same thing, get the world center of each object and calculate a vector between the two centers. Then force the object in the direction of the vector, scaled by its mass and the amount of force being applied.

F= ma
#6
12/13/2006 (11:33 am)
Those vectors are also passed as parameters to onCollision.

www.garagegames.com/mg/forums/result.thread.php?qt=36127

%this pointer is the pointer to the datablock
%obj is the object that is being collided with i.e. your player character
%col is the object that is doing the colliding i.e. your rocket
%buff1 is the vector of collision i.e. the rocket path
%buff2 is the scale of the vector i.e. the amount of force.

buff1: I read in gpgt has both the direction & magnitude of the collision
buff2: is the just the magnitude from buff1