Object keeps sliding after a collision

Topics: User Forum
Mar 5, 2009 at 6:20 PM
Good day everyone,

I'm having a little problem with my objects on the screen when they collide.

I have two tank texture converted to Geom using vertices, and they can fire missiles. When the missile hits another tank, the tank bounce and rotate depending on the missile's speed (this is all automatically done by farseer), and it's all good. 

However, the tank in question never seem to recover from the collision, it keeps sliding and rotating slowly ever. It looks like it's floating in the air but slowly.

How can I make it so that it stops sliding/rotating ? All the settings (mass, MOI, friction coefficient, etc) are all set to default, I didn't touch any of these).

Did I do something wrong ?


Thank you ;)
Coordinator
Mar 5, 2009 at 9:23 PM
Floating in the air? If it's resting on top of some sort of landscape, you just need to adjust the friction of the tank to make sure it stop.
Adjust the friction of the ground and the tank and see if it helps, if there is no change, try enabling debug view (you can get the debug view from our samples) to see what really happens.
Mar 6, 2009 at 3:54 AM
Edited Mar 6, 2009 at 3:55 AM
Hi genbox,

Thank you for the quick answer !


I've tried setting the tank's friction by pressing a button when the tank is "floating" but it didn't work.

By the way, there is no "ground". This is a top-down game, and currently the ground is nothing but the default blue background.

What I mean is that, after my missile collided with the tank, the tank bounce/slide/rotate on a certain distance depending on missile's speed and that's correct. But it never stop sliding lol, it keep sliding/rotating slowly just as if there was still a force applied on it, and when I move it using the keyboard; it works fine but as soon as I release the key, it starts sliding slowly again lol.

Sounds like I should clear every forces applied on the tank after a while.. I tried clearForce() and clearImpusle(), no success.

Think of it as an astronaute in the space, it keeps moving slowly due to gravity. (by the way I did set the gravity to 0 :P)

I'm really out of ideas lol.

What I want exactly is:
1. The missile hits the tank
2. The tank bounce/slides/rotate on a certain distante depending on the force of the impact (missile's speed/mass)
3. The tank recovers and just stops moving

Right now #1 and #2 work perfectly.

Mar 6, 2009 at 4:06 AM
Friction won't do anything if you aren't in contact with anything. Try playing with LinearDragCoefficient and RotationalDragCoefficient

Mar 6, 2009 at 4:34 AM
Hey ladron ;)


I tried playing with those and it didn't work either :(

In fact... the sample #2 in the samples that come with farseer represents exactly what's going on in my situation...
Make sure to remove the gravity (if any). When you hit the circle with the square, both entities keep "floating".

If you don't mind taking a look, that is exactly what I have.
My tank keeps floating/rotating just like the square or the circle when they hit each other.

Mar 6, 2009 at 4:39 AM
Edited Mar 6, 2009 at 4:40 AM
Wait...

I think I just forgot to do something here .. lol

genbox talked about ground, does that mean in a regular situation I must have a ground that is the size of the viewport (i.e: 800 by 600) which represents the "map" (or area displayed)  with a specific friction that would stop things from floating around ?

If so, to set a friction coefficient I need a geom. Would it be logic to set such a geom that must not collide with anything ?
Will the friction apply if the collision isn't enabled on the geom ?
Mar 6, 2009 at 5:01 AM
Actually it makes no sens, I just tried it.

I did set a ground Geom which has a width and height equivalent of the window's size.

I had of course to set CollisionEnabled = false, otherwise my tanks and everything would collide with it.
I've tried to set a FrictionCoefficient, but it doesn't seem to apply since the CollisionEnable is set to false..


Any suggestion ?

(Just a remmember: my situation is the exact same thing as in the sample #2)
Coordinator
Mar 7, 2009 at 12:05 AM
Friction is only applied when 2 objects are in contact. If that is not the case, friction won't work.

Even with no gravity, you still have a medium that the objects need to travel trough. The slowdown (drag) of traveling trough this medium can be controlled by changing LinearDragCoefficient (as ladron mentioned). If you insert the lines:

_circleBody.LinearDragCoefficient = 1f;
_rectangleBody.LinearDragCoefficient = 0.1f;

into the LoadContent() method in demo2, you will see a difference in the "floating".

Mar 7, 2009 at 3:46 AM
Yeah I noticed the change, but they still keep floating around, but even more slowly.

In my case I use tanks, and I don't want them to float around after an impact. It wouldn't be really realistic to see a tank floating slowly in the air during couple of minutes like the rectangle and the circle in the sample #2.

I wish it could stop from rotating and moving after some distance.
Mar 9, 2009 at 10:12 AM
It just occurred to me: if you turn on the Inactivity controller, it should stop the spinning/moving of your tank after a certain amoount of time automatically.
Coordinator
Mar 9, 2009 at 10:19 AM
@domynation: Have you tried with higher values for drag? Drag is the amount taken off the velocity and a higher value makes the bodies slow down faster (and stopping in the end).

@RCIX: Using the inactivity controller would also disable the body. That is what it's made for. To stop a body from rotating / moving after some time or under a certain velocity, just make a check in the Update() method:

if (tankBody.LinearVelocity < new Vector2(10,10))
tankBody.LinearVelocity = new Vector2(0,0);

Note: code is just an example to illustrate the concept in code.
Mar 9, 2009 at 11:00 AM
Ah. i thought when the body was disabled that it's motion wasn't kept, though.