Need resources on raycast suspensions/springs.

Started by
1 comment, last by vadevaman 9 years, 11 months ago

Hi, could someone post resources to raycast suspensions/springs ?

I'd like to re learn some bits of this aspect, I might have gone on a wrong bath

I'm facing a problem where my rest length is causing the normal force to be zero (as if it the ray distance had an offset)

I'm using physX as my physics engine.

This is a cut down code of what I do:


// -----> Init
const float radius = 0.3f;			// static ray offset (30cm)
const float length = 0.150f;		// the ammount the suspension can travel (150mm)
const float restLength = 0.100f;	// actual spring position (100mm)

const float springK = 55000;		// Spring stiffness
const float daperRate = 2500;		// Spring friction

float rayMaxLength;	// define the maximum length at where ray works
float rayDistance;	// ray's actual distance

float x0p;	// previous compresion (for velocity calcs)
float x0;	// current compression
float dV;	// damper velocity
float sF,dF;// Forces (spring / damper)
float suspensionForce;
float normalForce;

// -----> The loop at 1000hz
rayMaxLength = length+radius;			// spring max length + radius should be the correct way of initializing the ray lengt?
rayCast = CreateNewRay(rayMaxLength);	// ray function here
rayDistance = rayCast.distance;			// get actual picking distance (but where does this offset come from?)

// Compresion
x0p = x0;
x0 = (length - (rayDistance - radius));

// Force calcs
sF = springK * (x0-restLength); // after removing rest length the forces get fixed
dV = (x0 - x0p) / timeStep;	
dF = daperRate * dV;

// Resulting vertical force
suspensionForce = sF + dF;

// Normal force (for some reason this goes negative when compression is really small, (50mm) )
normalForce = sF;

// Normal force cant go negative...
if (normalForce<0.0f)
	normalForce = 0.0f;

In bullet's raycar I noticed that the maximum ray length is restLength + radius. But imo it should be length + radius. Am I right or wrong?

The funny thing here is also that in my C# vaersion of the code the normal force doesnt go negative, while in identical C++ code it goes...

Advertisement
Actually after this:

if (normalForce)
	normalForce = 0.0f;

normalForce will be 0.0f. Always.

oh sorry my bad, fixed it

This topic is closed to new replies.

Advertisement