Posted By: coma
Very Basic Physics - 07/30/04 02:57
can anyone help.
i can not find anywhere a basic coding showing with comments
how you make basic physics objects.
what i am trying to do is attach 2 blocks and add an hinge
i need to know the very basic off setting each object the world physics
if anyone could help
i would be gratefull.
thanks CoCo
Code:
ENTITY* pObject1;
var hHinge;
action Object1
{
phent_settype(my, PH_RIGID, PH_SPHERE); //make physics entity
pObject1= my; // store for later reference
}
action Object2
{
while (pObject1==0) { wait(1); } // wait until object1 is ready....
phent_settype(my, PH_RIGID, PH_SPHERE); //make physics entity
hHinge= phcon_add(PH_HINGE, pObject1, my ); // join the two and store handle
ph_setgravity( vector(0,0,-400) ); // activate gravity
}
Now create a level with two models in it and assign action Object1 to one of them and Object2 to the other. Once you got that working read the manual on constraints and how to set up the details.
Posted By: coma
Re: Very Basic Physics - 07/30/04 05:38
is there anyway that you can join the objects in a certain place
for e.e
top left on 1 object
& bottom right on another 1
No, they are always joined at their center of gravity.
Posted By: coma
Re: Very Basic Physics & Collide - 08/01/04 04:07
with this script below the balls bounce around but how could a call an event when the balls collide with a certain object in the level
thanks coma
////////////////////////////////////////////////////////////////////////////////////
var video_mode = 8; // 800x600 pixels
var video_depth = 32; // 32 bit mode
////////////////////////////////////////////////////////////////////////////////////
string mypro_wmb = <mypro.wmb>;
string box_mdl = <ball.mdl>;
////////////////////////////////////////////////////////////////////////////////////
var box_pos;
function makebox();
function create_box();
entity* box_ptr;
//x = random(2)-1; // x is set to a number between -1.0 and 0.999999
function main()
{
level_load (mypro_wmb);
wait(3);
camera.x = 0;
camera.y = -600;
camera.z = 240;
camera.pan = 90;
camera.tilt = -15;
box_pos.x = random(25)-25; // initial value, ranges from -95 to 105
box_pos.y = -71;
box_pos.z = 295;
}
function makebox()
{
box_pos.x = random(25)-25; // initial value, ranges from -95 to 105
box_pos.y = random(71)-71;
box_pos.z = 495;
box_ptr = ent_create(box_mdl, box_pos,create_box);
wait(1);
}
function create_box()
{
phent_settype(my, ph_rigid, ph_sphere); // enable physics for this ball
phent_setmass(my, 1, ph_sphere); // the ball has 1kg (2 lbs) and behaves like a sphere
phent_setfriction(my, 50); // friction
phent_setelasticity(my, 99, 0); // bounce a little
temp.x = 0;
temp.y = 0;
temp.z = -380; // earth gravity factor, g = 9.81 m/s2
ph_SetGravity(vector(0,0,-50 0)); // set gravity
while (my.z > -50) {wait (1);} // the ball has approached the floor
// sleep (1); // give it 3 more seconds
phent_setelasticity(my, 5, 0); // stop bouncing
phent_setmass(my, 10, ph_sphere); // the ball has 1kg (2 lbs) and behaves like a sphere
sleep (15); // give it 3 more seconds
phent_settype(my, 0, ph_sphere); // now stop the ball
// box_ptr = null; // free the pointer - we will assign it to a new ball
}
on_space=makebox;