   Cars, cars and also ... cars
  Hmm, I see everybody's trying to simulate cars. I am trying, too. What I'm trying to do is an arcade off-road racing game. Something like monster-trucks chasing one another over some huge height-mapped terrain. The problem is that now all the cars are like glued to the ground: they can climb almost vertical slopes, if you go very fast towards a hole in the ground, instead of flying over it, the car will fall and then climb back up, etc. These things are ruining all the game. So after discovering the verlets, I tried to integrate them into my engine. The result: disaster!   I placed some vertlets in the car's corners connected with stick constraints to handle collision detection and 4 for the 4 wheels (4 4 the 4, nice!). Now my cars can collide one another and flip over (well, it's not very realistic, because I haven't implemented friction yet, and they slide downhill instead of rolling) but I can't get them running.   I have the engine's RPM and only one gear (just to keep everything simple). Now, how do I make my car go forward? I don't think it'll work if I just move the 4 wheel vertlets forward by some distance (based on the RPM, wheel radius, etc).    Another problem is friction. If the car is heavily pressing on the ground, it's wheels will move it forward. But if the wheels are barely touching the ground (let's say the car is just landing after flying a little in the air) then they will spin faster but the car won't move. (it would be easier to draw, but I'm not very skilled in ASCII art  ). Also about the friction, how can I calculate it for a vertlet (one of those in the car's corners) 'cause I'd really like to see my cars rolling downhill instead of sliding.   One more question: is the vertlet integration scheme good for these kind of things, or should I considere another way of solving? (Well, if the answer to this question is NO, then all the other questions are useless).   Thx in advance for any help you can provide.Have FUN,FeeL E![edited by - filisoft on February 13, 2004 7:49:08 AM]
  Could you post a link to where you found aout about vertlet stuff? It sounds something I''d like to use; maybe after reading it I could suggest something too! ;  The best article is from the one that invented these verlets (it seems it''s verlet, not vertlet. my mistake). You can find the article at gamasutra: http://www.gamasutra.com/resource_guide/20030121/jacobson_01.shtmlThere are some examples here, but very basic. Anyways, it''s a nice article.   Have FUN,FeeL E! ;  I found a great demo: http://www.highgearsolutions.com/nexus/upload/andreas/verlet2d/jeep3dexe.zipThis is exactly what I want to do. I found it on andreas_blixt's homepage (I think...)Have FUN,FeeL E!   [edited by - filisoft on February 13, 2004 8:28:30 AM];  his is really 2D. for 3D, the same principle applies, but mo re complicated. to move the car, this is what I suspect he does. When pressing the throttle, he applies a torque to the wheel, which makes them spin, and using the contact velocity on the floor and the grip on the tyre, it generates a force that pushed the wheel forward. In turn, it pushed the chassis forward through the stiff constraints. to move it to 3D, it''s basically the same thing. Only it''s done on spheres and triangles, not circles and segments.  ;  Yes, oliii, it's in 2D. I had a look in his sources and saw that he's using nine particles for one wheel: one in center and eight on the contour. And again, you're right: to move, both wheels are rotated around the center particle. No contact pressure, velocity, nothig. And the final result is quite good-looking.I've implemented this and it's kind of working, but not very well. You have a demo at http://www.filisoft.as.ro/wh1.zip. The wheel keeps it's shape but sometimes I get collisions where there shouldn't be. For example, just when the wheel collides with the obstacle, the middle particle turns red (this means a collision) but it's no collision...Right click resets the simmulation.If anybody will look in my source, then:The FRICTION is defined 1=no friction, 0=full friction.BOUNCY=how much will jump (around 5 is nice, more gets out of control).The main simulation function is update_particles().Any ideas? Thx. Have FUN,FeeL E!   [edited by - filisoft on February 14, 2004 4:55:21 AM];  I finally got it! Just some wrong index in the collision detection routine. Now it's allmost right. Check this: http://www.filisoft.as.ro/wh2.zip. There's only one problem: sometimes the "car" gets totally blown away. Increasing the BOUNCY solved it but now the car skids a lot. Increasing the friction to total friction (FRICTION=0) didn't solve it. I guess it's because in the collision detection I move the new position, but I leave unchanged the old one. Do you think I should modify the old position too?   BTW, I forgot: Left mouse button to go left, Right mouse button to go right and Space to reset.Have FUN,FeeL E!   [edited by - filisoft on February 14, 2004 6:35:22 AM];  nice I had some fun with setting the constraint iterations to just 2. makes the wheel constraints a lot softer, so more grip, and the tire deforms more as well. you''ll probably need to setup springs constraints, to make the car less rigid. also, try this )  dx=part[cons[i].p2].x-part[cons[i].p1].x;dy=part[cons[i].p2].y-part[cons[i].p1].y;deltalen=sqrt(dx*dx+dy*dy);diff=(deltalen-cons[i].len)/deltalen;diff *= 0.2f; // cons.rigidity;<br></font><br>moveParticle(cons[<font color=purple>i</font>].p1,dx*0.5*diff,dy*0.5*diff);<br>moveParticle(cons[<font color=purple>i</font>].p2,-dx*0.5*diff,-dy*0.5*diff);<br></pre><!–ENDSCRIPT–><br>   ;  so basically, you can control the stability and rigidy of hte system by tweaking the constraint''s rigidity, and the overall system rigidity (the number of constraint iterations per frame). you can increase the friction by quite a lot, and still keep the system stable. ;  Thx, I''ll try. Setting the iterations to 2 causes the tires to wobble. 4 or 5 is optimum. I solved the friction problem very easy (after boiling my brains): when I move back the particle after a collision also move the old position back the same ammount. This way I could make the wheels less bouncy. Wheels less bouncy means more friction. Also wheel size matters. A lot. You can have a new demo at http://www.filisoft.as.ro/wh3.zip.Left and right mouse buttons move car, space resets, page up / page down modifies the wheel radius.I had some fun making huge tires and climbing very high.Heh, springs were my next questions, but oliii answered before asking. Thx. I think that with that rigidity thing I can make some cool suspensions. Right?   Have FUN,FeeL E! 