4 registered members (AndrewAMD, VoroneTZ, Quad, 1 invisible),
837
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
hinge physics- making it stay
#34713
10/09/04 15:32
10/09/04 15:32
|
Joined: Jul 2003
Posts: 1,300 Albury, Australia
James_Burke
OP
Serious User
|
OP
Serious User
Joined: Jul 2003
Posts: 1,300
Albury, Australia
|
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
|
|
|
Re: hinge physics- making it stay
[Re: James_Burke]
#34714
10/09/04 16:58
10/09/04 16:58
|
Joined: Aug 2001
Posts: 2,320 Alberta, Canada
William
Expert
|
Expert
Joined: Aug 2001
Posts: 2,320
Alberta, Canada
|
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.
|
|
|
|