I checked the time-dependance code and it looks just like what you posted, except I didn't use temp variables. I stuck the calculation where you hade the temp variable. Here's the code (note: for some reason I call the guy's velocity vector heading. Must be too much Star Trek)
net_force.x = spring_force.x + surface_force.x + gravity_force.x; net_force.y = spring_force.y + surface_force.y + gravity_force.y; net_force.z = spring_force.z + surface_force.z + gravity_force.z; net_force.find_magnitude(); //vector A; acceleration.x = net_force.x / MASS; acceleration.y = net_force.y / MASS; acceleration.z = net_force.z / MASS; acceleration.find_magnitude(); heading.x += acceleration.x * i; heading.y += acceleration.y * i; heading.z += acceleration.z * i; heading.find_magnitude(); position.x += heading.x * i; position.y += heading.y * i; position.z += heading.z * i;
I know I'm going at this bass-ackward, but I needed to keep rotation code to a minimum, so that I would be working with a standard position on an uneven ground, test subject and control subject. I do like your idea, so I'll implement that once I get rotational motion in place.
So, you said that the spring system was all off. I set it up like this:
1. test for collision
2. if collision, get the surface normal of the ground
3. calculate force and direction spring exerts on mass-spring
4. calculate force that ground exerts on spring-mass
5. Add gravity, spring force, and ground force
If there is no collision, there is no ground force. When there is a collision, the force of the spring is calcuated by using the last position and the current velocity to figure out how much the spring compresses. Then, the center of the spring-mass is moved to that point. Notice that I don't do anything about the spring's "foot", I just consider it a certain distance from the center of the body and move according to the compression of that spring.
While typing that last sentence, I just thought about something. Maybe I'm forgetting to "remember" the last amount of compression the spring experiences, so that each frame it starts at no compression. I'll check my code again for that. I'll go do that now.
edit: Well, I changed that so it did fix some stuff. It now bounces more naturally. The code now says
if(collision){ //blah}else{ spring_compression = 0;}spring_compression += spring_compression_ratio * heading.magnitude; spring_force.x = b.x * SPRING_CONSTANT * spring_compression; spring_force.y = b.y * SPRING_CONSTANT * spring_compression; spring_force.z = b.z * SPRING_CONSTANT * spring_compression; spring_force.find_magnitude();
Wow, now I feel like I'm actually getting somewhere! It kinda works! It compiles, ship it! :)
[Edited by - DuncanBojangles on July 6, 2004 1:38:16 AM]