hinge physics- making it stay

Posted By: James_Burke

hinge physics- making it stay - 10/09/04 15:32

Hi,
I'm don't know anything much about physics. So you'll have to excuse my noobiness when it comes to physics

I've been adapting the code from 3PM Feb, and here's what I have:
Code:
  
//-----------------------------
//Variable Defines
//-----------------------------
//Temp physic variables
var h_id;
var p2[3];
var p3[3];
var p4[3];
var p5[3];
var p6[3];
var door_max[3];

//-----------------------------
//Pointer Defines
//-----------------------------
entity* hinge; //Hinge pointer

//-----------------------------
//Actions
//-----------------------------
//---------------
//Desc: Hindge which connects the door
//---------------
action hinge_ent
{
hinge = my; //Give it the hinge pointer
my.passable = on; //Passable
wait(1);
}

//---------------
//Desc: A standard door
//---------------
action door
{
while(player == null)
{
wait(1); //Prevents empty pointers
}
phent_settype(my, ph_rigid, ph_box); //Is a physics object
phent_setgroup(my, 2);
phent_setmass(my, 100, ph_box);
phent_setfriction(my, 10);
phent_setelasticity(my, 2, 1);

//Sets the parameter vectors
vec_set(p2, vector(0, 0, 1));
vec_set(p3, vector(0, 0, 0));
vec_set(p4, vector(-90, 90, 0));
vec_set(p6, vector(0, 0, 0));

h_id = phcon_add(ph_hinge, my, hinge); ///Enables a 'hinge' joint

//Set the parameters
phcon_setparams1(h_id, hinge.x, p2, nullvector);
phcon_setparams2(h_id, p4, nullvector, nullvector);

//Set the speed
vec_set(door_max, vector(20, 10, 0));
phcon_setmotor(h_id, door_max, nullvector, nullvector);
}



Now, the problem is the door keeps going away from the hinge, which it shouldn't do. Have I missed something?
Here's a pic of it set up in WED incase there's a problem with that:


And here's the result:


Thanks for any help,
James
Posted By: William

Re: hinge physics- making it stay - 10/09/04 16:58

I tested the code that you posted with my models from the 3PM article. It worked fine for me... You should change this line so it works better(you must have typed it wrong):
What you had:
h_id = phcon_add(ph_hinge, my, hinge);

Change To:
h_id = phcon_add(ph_hinge, my, 0);

The reason for this is that you are not needing to set up 2 contraints with ph_hinge. Ph_wheel for an example, requires two contraints(the wheel, and the body), but with a hinge constraint you only need one which would be the door entity.

I doubt changing that line will fix it for you, it is most likley an origin problem with your models. Are you origins set right in MED? The origins of the models in MED is where the two objects connect via the constraint, if these are set wrong then you will experience very weird behaviour since it will be rotating itself around the messed up origin. As you may know, "my.x" is the origin of the entity in MED. Since the anchor point of the door entity is "hinge.x", your door model will swivel around the origin of the hinge model. Load up the models that I used in 3PM and look at how I set up the origins and duplicate it for your models.
Posted By: James_Burke

Re: hinge physics- making it stay - 10/09/04 18:13

Thanks,
That worked, but now for some reason, I can go one way ok, but I can't go back. Any advice there?
Thanks again,
James
Posted By: William

Re: hinge physics- making it stay - 10/10/04 05:01

Its going both ways for me. I'm not exactly sure what your problem there would be. Though, I have noticed that it can tend to get slightly stuck in the wall if you hit it hard enough and keep on pushing it into the wall. Try fiddling with the amount you have set for the contraints motor.
Posted By: James_Burke

Re: hinge physics- making it stay - 10/10/04 07:40

Thanks, that's proberly the problem
© 2024 lite-C Forums