This project has moved and is read-only. For the latest updates, please go here.

'Soft' Surfaces

Topics: User Forum
Aug 4, 2011 at 11:40 AM

I'm loving Farseer Physics, but am frustrated that something that seems so obvious still escapes me!

How would I simulate the kind of friction that you might see in a golfing game; The golf ball can be hit off the tee, and land on surfaces that affect the volocity differently - the ball could land on the fairway, or perhaps a sand trap.

I have a sloped surface (edge) that I use for my sandtrap, but the ball always rolls around until it finds somewhere to settle. What I need is a kind of 'stickyness' of the two bodies. The ball is not sticky, of course, but the stickyness of the edges would vary depending on the 'quality' of the impact surface: fairway, fringe, green or sand.

Of course, applying a force to the ball along the contact normal shouldn't be affected, only forces along the tangent normal for the particular contact surfaces.

I'm no physics expert, so please excuse my ignorance in this area, and if I have misused any terminology!


Aug 4, 2011 at 2:39 PM

hmmm if i understand you right you want to make the sand "sticky"

try to set the sand body to a sensor and if it contains the golf ball slow him down. you can do ramps like that too (but instead of slowing down push it facting the normal / direction)

you also can set body.LinearDamphing (i think) to something like 1f or whatever

Aug 5, 2011 at 12:25 PM

What you want to do is adjust the friction. I'm still fairly new at Farseer, but I believe that all bodies have a friction variable that can be set. In your case, you would adjust the friction of the "sand trap" edges to be higher than any other surface. If that's not possible, you will have to adjust the friction of the ball. You could set if statements up to adjust the friction of the ball depending on the surface it is on. Something like this this pseudo code.

if(surface == fairway)

Ball.Friction = 0.1f;

else if(surface == sand)

Ball.Friction = 5f;

Aug 5, 2011 at 1:04 PM

Thank you both for your replies! Unfortunately, I have tried these techniques already, with little success. :(

LineadDamping is factored in after gravity is applied to the internal linear volicity. Unless the damping value is incredibly high it will not completely stop the ball.  If I set the damping value proportionally to velicity (approaching infinity as the velocity decreases) I get something akin to what I am after; however, a slowing ball in sand will never roll backwards, regardless of the slope-angle, which means it looks incredibly unnatural.

Friction is used in the collision solver when processing velocity constraints. It seems to be used to determine how much energy is transferred from one surface to another when they are in contact but moving relative to each-other. The energy transfer is limited by the normal impulse scaled by the friction factor. Friction on a sphere with a static edge will only result in rotational velocity being added to the ball. :/

I'm trying to find a nice place to add 'surface dynamics' into this calculation, but as I said, I'm no expert.

Again, thank you both for your ideas - keep 'em coming!

Aug 5, 2011 at 6:01 PM

You could filter the collisions and check them in the update method. Then, if a collision betwen two specific bodies occur change whatever you need. In the case of a sand ramp I would use a normal force from the ball to the sand so make it "stick".