Recommended Posts

I'm messing about remaking a small platform game that I made for my Amiga a few years ago, but this time I'm doing everything properly. :-)
I'm writing the collision code at the moment, I've hit a bit of a snag. I'm not very experienced with collision so I was hoping somebody could help me out.
I represent my world as a collection of convex areas. I've got collision done where on intersection I just slide the object out of the surface along its normal. That works great, and I've got a good stable collision system with it, but now I want to stop the objects sliding if they are colliding with the ground and the
slope is too shallow.
So instead of moving the object out along the normal I stop it at the intersection point. This is dodgy because if you're standing on ground, the intersection point is always where you are. This stops me being able to move my character because the collision always gets resolved back to where he started from. Damn!
Has anyone dealt with that before?
Thanks in advance for any help.
- Peter
Why you shouldn't use iostream.h - ever! | A Good free online C++ book[edited by - siaspete on June 3, 2003 6:41:43 AM]

0

Share this post

Link to post

Share on other sites

Sure, no problem.I just finished a kind of physics-engine with friction and all the stuff. As far as you don''t want the body to start rolling, it''s very easy. Only the rotating thing was a little bit difficult.Ok, let''s start.First you have to get the normal of the surface.Afterwards you need the force towards the surface. f1 = n.x*force.x + n.y*force.yn is a vector representing the normal of the surface and force the forces applied to the body.Further more you need two coefficients,µg and µh values for the friction if the body is sliding(µg) and if it''s not moving on the floor (µh).µg is always smaler than µh.Either you experiment and choose values you like or you get a collection of physical tables were you find the values for material1 on material2. A tire on an dry street has µg < 0.3; µh < 0.8;Just in case you got rubber and (...asphalt...), rubber and street.Now you can calculate the friction. Fg = f1*µg Fh = f1*µhThe directions are the opposite of the velocity along the surfaceso multiply it withsgn(v) and v you get a.x = -n.y and a.y = n.x, v = Vel.x*a.x + vel.y*a.y-n.y and n.x is because this represents a vector along the surface withmaybe you got to use v.x = n.y and v.y = -n.x, but I don''t think so.The same way you get the force down the hill. f2 = force.x*(-n.y) + force.y*n.x If you need a vector f2v.x = f2*a.x f2v.y = f2*a.yAnd now you are nearly done.If f2 is greater than Fh the body starts sliding, if not it doesn''t do anything, if v is not zero you calculate a vector for the friction like Fgv.x = -Fg*a.x Fgv.y = -Fg*a.yand apply it to the body.You should only pay attention if Fg is applied that you calculate if the new velocity is getting zero if he slides long enought. Maybe likeIf sgn(Fg) <> sgn(f2) then you check if the new velocity'' abs is smaller then the one before if not it''s ZERO.sgn(x) = signum, function that returns -1 if x<0; 0 if x=0 and +1 if x > 0abs(x) = absolut value, returns x if x>=0 and -x if x<0 so that you always get a positiv value.Hope I could help.I''m still searching for a place to upload my physic-engine if my friend finishes the graphic so that I can translate my engine from VB in VC.

Share this post

Link to post

Share on other sites

That''s to much honor, it''s just that I love progrmming and a specialy if it''s physics. This morning (MET) I solved a problem wit the sliding and so on, because of the "incorrectnes" the body did not move on the surface it did tiny jumps not even noticeable so it was on the surface, then for a milisecond not...and so it started to slide, stoped,... and so on, I don''t know why I needed so long to solve this problem, but I simply put in a constant tolerance and so if the body is a little bit above the surface it''s still on it same with sliding and so. And now the movement looks really GREAT. I would make a salto backwards if I could, that''s the kind of fun it makes while programming, get a solution and make things looking smooth.

0

Share this post

Link to post

Share on other sites

Don''t forget toppling! You don''t want long tall objects sliding down slopes with a large gradient! ( basically, if the centre of gravity of the object is past the last point of contact with the surface ( down the slope ), then it''ll fall over ).