6D Joints / Hinge Joints and vehicles

Posted By: Rei_Ayanami

6D Joints / Hinge Joints and vehicles - 07/29/12 20:55

Hey guys!

I am currently working on car physics (using PhysX in A8) and I
have stumbled upon a problem: the wheels.

Generally the PhysX SDK would provide wheel functions, however,
they are not included in the GS-Wrapper. Furthermore, I cannotuse
the raycast-wheel GS delivers, because I need to have more settings
on the wheel (like mass, friction etc, that actually has an effect
on the wheel).

Now I tried hinge joints using an extra entity for the control-able
wheels (usually the front ones), but that did not work, as the
chassis did not move, though the "extra entity" did.

6D Joints added a lot of oscillating of the wheels and I was not
able to add rotation, as the angles were rotated (means, when I
rotated the wheel's pan, the tilt was rotated as well).

Anyone could point me in the right direction for Gamestudio?

Thanks in advance and best regards,
Rei
Posted By: HeelX

Re: 6D Joints / Hinge Joints and vehicles - 07/30/12 07:46

I had success with connecting a convex shaped-wheel entity with a chassis using a 6D-joint. All you have to do is to enable linear motion on the y-axis (up) and angular motion around the x-axis (forward) and y-axis (up) and set velocity as drive type, as well as constraints. If that doesn't work out for you, make two 6D joints. Don't use regular joints, like hinges or so, they are only intended for what they are designed for. Then, instead of applying forces on the wheels, I had good results with just adding a velocity to the chassis - the wheels will react then properly.
Posted By: Rei_Ayanami

Re: 6D Joints / Hinge Joints and vehicles - 07/30/12 14:01

The linear motion on the Y-axis is for damper, right? (Because damping is not really a need for me)

A convex shape fails, as some of the tires are just to low res, which results in a really un-smooth behavior.

However, my biggest problem is still the steering. Not locking the other two rotation dimensions results in uncontrollable behavior (even with LIMITED and limits set to 0). Using an additional entity and an additional 6D joints results in "lagging" of the wheel (behind the additional entity). The additional entity also behaves odd. I guess this could be related to the masses of the objects?
Posted By: HeelX

Re: 6D Joints / Hinge Joints and vehicles - 07/30/12 14:06

You can upload another shape to the wheel, of course. Just take the convex hull of a cylinder and put it on the wheel. You can do that with my PhysX plugin.

Maybe you can show some code, or better: A small demo which can be inspected by others. Making a correct physics setup is a daunting task sometimes and maybe you or I overlook something here.
Posted By: Rei_Ayanami

Re: 6D Joints / Hinge Joints and vehicles - 07/30/12 14:45

Here is a example that uses the gamestudio CUBE_MDL (that shows the movement of wheels quite good).

Code:
#include <acknex.h>
#include <default.c>
#include <ackphysx.h>


void main()
{
	/* Init */
	wait(1);
	level_load(NULL);
	physX_open();
	
	camera.x = 218;
	camera.y = 442;
	camera.z =  81;
	camera.pan = 247;

	ENTITY* ground = ent_create(CUBE_MDL,vector(0,0,0),NULL);
	vec_set(ground.scale_x,vector(100,100,1));
	pXent_settype(ground,PH_STATIC,PH_BOX); 
	pXent_setfriction(ground,90);

 
	/* Vehicle */
	var motion[6] = { 0, 0, 0, NX_D6JOINT_MOTION_FREE, 0, 0};
	var drive[6] = { 0, 0, 0, NX_D6JOINT_DRIVE_VELOCITY, 0, 0 };

	VECTOR pos;
	vec_set(pos, vector(0,0,100));


	ENTITY *chassis = ent_create(CUBE_MDL, pos, NULL);
	vec_set(chassis.scale_x, vector(10,5,4));

	pXent_settype(chassis, PH_RIGID, PH_BOX);
	pXent_setgroup(chassis, 2);
	pXent_setmass(chassis, 50);


	ENTITY *wheel1 = ent_create(CUBE_MDL, pos, NULL);
	vec_fill(wheel1.scale_x, 2);
	vec_add(wheel1.x, vector(60,60,-32));

	pXent_settype(wheel1, PH_RIGID, PH_SPHERE);
	pXent_setgroup(wheel1, 2);
	pXent_setmass(wheel1, 30);

	pXcon_add(PH_6DJOINT, wheel1, chassis, 0);
	pXcon_setparams1(wheel1, wheel1.x, NULL, NULL);
	pXcon_set6djoint(wheel1, motion, drive);

	ENTITY *wheel2 = ent_create(CUBE_MDL, pos, NULL);
	vec_fill(wheel2.scale_x, 2);
	vec_add(wheel2.x, vector(60,-60,-32));

	pXent_settype(wheel2, PH_RIGID, PH_SPHERE);
	pXent_setgroup(wheel2, 2);
	pXent_setmass(wheel2, 30);

	pXcon_add(PH_6DJOINT, wheel2, chassis, 0);
	pXcon_setparams1(wheel2, wheel2.x, NULL, NULL);
	pXcon_set6djoint(wheel2, motion, drive);

	ENTITY *wheel3 = ent_create(CUBE_MDL, pos, NULL);
	vec_fill(wheel3.scale_x, 2);
	vec_add(wheel3.x, vector(-60,60,-32));

	pXent_settype(wheel3, PH_RIGID, PH_SPHERE);
	pXent_setgroup(wheel3, 2);
	pXent_setmass(wheel3, 30);

	pXcon_add(PH_6DJOINT, wheel3, chassis, 0);
	pXcon_setparams1(wheel3, wheel3.x, NULL, NULL);
	pXcon_set6djoint(wheel3, motion, drive);

	ENTITY *wheel4 = ent_create(CUBE_MDL, pos, NULL);
	vec_fill(wheel4.scale_x, 2);
	vec_add(wheel4.x, vector(-60,-60,-32));

	pXent_settype(wheel4, PH_RIGID, PH_SPHERE);
	pXent_setgroup(wheel4, 2);
	pXent_setmass(wheel4, 30);

	pXcon_add(PH_6DJOINT, wheel4, chassis, 0);
	pXcon_setparams1(wheel4, wheel4.x, NULL, NULL);
	pXcon_set6djoint(wheel4, motion, drive);


	var accel;

	while(1)
	{
		accel = (key_w-key_s)*500;
		pXcon_setmotor(wheel1, vector(0,0,accel), 0);
		pXcon_setmotor(wheel2, vector(0,0,accel), 0);
		wait(1);
	}
}



This is only for driving forward and backward, as the wheels start spinning whenever I use NX_D6JOINT_MOTION_FREE / NX_D6JOINT_MOTION_LIMITED (with limits set).
Posted By: HeelX

Re: 6D Joints / Hinge Joints and vehicles - 07/30/12 15:04

I see what you mean. Try to add a second 6D joint, that connects the wheel joint with the chassis with a hinge-like constraint. Enabling the Y or Z axis makes no sense, thats right.
Posted By: Rei_Ayanami

Re: 6D Joints / Hinge Joints and vehicles - 07/30/12 16:58

I do not really get what you mean by this smirk

Because simply adding another joint (pXcon_add) between wheel and chassis disables any movement of the wheel.

Or do you mean by another entity?
Posted By: HeelX

Re: 6D Joints / Hinge Joints and vehicles - 07/31/12 09:50

Yes, create a virtual entity for the front wheels, so that you can rotate the wheels with no respect to their rotation about the chassis' up-axis (centered at the wheel origin).
Posted By: Rei_Ayanami

Re: 6D Joints / Hinge Joints and vehicles - 07/31/12 14:00

Okay, tried it. The result is not too bad (better than anything I achieved with 6D joints thus far), however, the front wheels just move into the ground.

The example is using CUBE_MDL.

Would be awesome if you could take another look at it laugh

Code:
#include <acknex.h>
#include <default.c>
#include <ackphysx.h>


void main()
{
	/* Init */
	wait(1);
	level_load(NULL);
	physX_open();
	
	camera.x = 218;
	camera.y = 442;
	camera.z =  81;
	camera.pan = 247;

	ENTITY* ground = ent_create(CUBE_MDL,vector(0,0,0),NULL);
	vec_set(ground.scale_x,vector(100,100,1));
	pXent_settype(ground,PH_STATIC,PH_BOX); 
	pXent_setfriction(ground,90);

 
	/* Vehicle */
	var motion[6] = { 0, 0, 0, NX_D6JOINT_MOTION_FREE, 0, 0};
	var drive[6] = { 0, 0, 0, 0, 0, 0 };

	var motionRot[6] = { 0, 0, 0, 0, 0, NX_D6JOINT_MOTION_LIMITED};
	var driveRot[6] = { 0, 0, 0, 0, 0, 0 };

	VECTOR pos;
	vec_set(pos, vector(0,0,100));


	ENTITY *chassis = ent_create(CUBE_MDL, pos, NULL);
	vec_set(chassis.scale_x, vector(10,5,4));

	pXent_settype(chassis, PH_RIGID, PH_BOX);
	pXent_setgroup(chassis, 2);
	pXent_setmass(chassis, 50);


	ENTITY *wheel1Rot = ent_create(CUBE_MDL, pos, NULL);
	vec_add(wheel1Rot.x, vector(60,60,0));

	pXent_settype(wheel1Rot, PH_RIGID, PH_BOX);
	pXent_setgroup(wheel1Rot, 2);
	pXent_setmass(wheel1Rot, 30);

	pXcon_add(PH_6DJOINT, wheel1Rot, chassis, 0);
	pXcon_setparams1(wheel1Rot, wheel1Rot.x, NULL, vector(999,999,999));
	pXcon_setparams2(wheel1Rot, vector(30,30,30), vector(0,30,0), vector(999,999,999));
	pXcon_set6djoint(wheel1Rot, motionRot, driveRot);

	ENTITY *wheel2Rot = ent_create(CUBE_MDL, pos, NULL);
	vec_add(wheel2Rot.x, vector(60,-60,0));

	pXent_settype(wheel2Rot, PH_RIGID, PH_BOX);
	pXent_setgroup(wheel2Rot, 2);
	pXent_setmass(wheel2Rot, 30);

	pXcon_add(PH_6DJOINT, wheel2Rot, chassis, 0);
	pXcon_setparams1(wheel2Rot, wheel2Rot.x, NULL, vector(999,999,999));
	pXcon_setparams2(wheel2Rot, vector(30,30,30), vector(0,30,0), vector(999,999,999));
	pXcon_set6djoint(wheel2Rot, motionRot, driveRot);


	ENTITY *wheel1 = ent_create(CUBE_MDL, pos, NULL);
	vec_fill(wheel1.scale_x, 2);
	vec_add(wheel1.x, vector(60,60,-32));

	pXent_settype(wheel1, PH_RIGID, PH_SPHERE);
	pXent_setgroup(wheel1, 2);
	pXent_setmass(wheel1, 30);

	pXcon_add(PH_6DJOINT, wheel1, wheel1Rot, 0);
	pXcon_setparams1(wheel1, wheel1.x, NULL, NULL);
	pXcon_setparams2(wheel1, vector(30,30,30), vector(0,30,0), vector(999,999,999));
	pXcon_set6djoint(wheel1, motion, drive);

	ENTITY *wheel2 = ent_create(CUBE_MDL, pos, NULL);
	vec_fill(wheel2.scale_x, 2);
	vec_add(wheel2.x, vector(60,-60,-32));

	pXent_settype(wheel2, PH_RIGID, PH_SPHERE);
	pXent_setgroup(wheel2, 2);
	pXent_setmass(wheel2, 30);

	pXcon_add(PH_6DJOINT, wheel2, wheel2Rot, 0);
	pXcon_setparams1(wheel2, wheel2.x, NULL, NULL);
	pXcon_set6djoint(wheel2, motion, drive);

	ENTITY *wheel3 = ent_create(CUBE_MDL, pos, NULL);
	vec_fill(wheel3.scale_x, 2);
	vec_add(wheel3.x, vector(-60,60,-32));

	pXent_settype(wheel3, PH_RIGID, PH_SPHERE);
	pXent_setgroup(wheel3, 2);
	pXent_setmass(wheel3, 30);

	pXcon_add(PH_6DJOINT, wheel3, chassis, 0);
	pXcon_setparams1(wheel3, wheel3.x, NULL, NULL);
	pXcon_set6djoint(wheel3, motion, drive);

	ENTITY *wheel4 = ent_create(CUBE_MDL, pos, NULL);
	vec_fill(wheel4.scale_x, 2);
	vec_add(wheel4.x, vector(-60,-60,-32));

	pXent_settype(wheel4, PH_RIGID, PH_SPHERE);
	pXent_setgroup(wheel4, 2);
	pXent_setmass(wheel4, 30);

	pXcon_add(PH_6DJOINT, wheel4, chassis, 0);
	pXcon_setparams1(wheel4, wheel4.x, NULL, NULL);
	pXcon_set6djoint(wheel4, motion, drive);


	var accel;
	var steer;

	while(1)
	{
		accel = (key_w-key_s)*500;
		steer = (key_a-key_d);
		if(!steer)
		{
			pXcon_setparams2(wheel1Rot, vector(30,30,30), vector(-0.1,0.1,0), vector(999,999,999));
			pXcon_setparams2(wheel2Rot, vector(30,30,30), vector(-0.1,0.1,0), vector(999,999,999));
		}	
		else if(sign(steer) == -1)
		{
			pXcon_setparams2(wheel1Rot, vector(30,30,30), vector(-0.1,30,0), vector(999,999,999));
			pXcon_setparams2(wheel2Rot, vector(30,30,30), vector(-0.1,30,0), vector(999,999,999));
		}
		else
		{
			pXcon_setparams2(wheel1Rot, vector(30,30,30), vector(-30,0.1,0), vector(999,999,999));
			pXcon_setparams2(wheel2Rot, vector(30,30,30), vector(-30,0.1,0), vector(999,999,999));
		}
		pXent_addtorquelocal(wheel1Rot, vector(0,0,steer));
		pXent_addtorquelocal(wheel2Rot, vector(0,0,steer));
		pXent_addtorquelocal(wheel1, vector(0,accel,0));
		pXent_addtorquelocal(wheel2, vector(0,accel,0));
		wait(1);
	}
}


Posted By: MasterQ32

Re: 6D Joints / Hinge Joints and vehicles - 07/31/12 14:35

maybe you should use an dummy entity (ent_create("", ...)) instead of CUBE_MDL
should work better because it has no collision shape
Posted By: Rei_Ayanami

Re: 6D Joints / Hinge Joints and vehicles - 07/31/12 16:08

6D Joints need registered shapes, else you will get a crash wink
Posted By: Rei_Ayanami

Re: 6D Joints / Hinge Joints and vehicles - 08/01/12 11:57

Any other ideas?
Posted By: 3run

Re: 6D Joints / Hinge Joints and vehicles - 08/08/12 15:22

I'm also interested in this guys! C'mon, leand a hand.
© 2024 lite-C Forums