# Creating bunker (sand area) in Golf Game

Hello everyone

I am coding a golf game that is part of an university assignment.

The game is almost finished (alpha release) except for some details, among them, I have not been able to create a golf bunker (area that has sand).

Playing with materials I have managed to make the golf ball not to bounce when crashing in the sand, but I have not been able to make it stay there, instead of continue rollling.

How should I solve this problem using JME apis and not and ad hoc solution?

I'm going to assume you are using jME Physics for this. Based on that assumption, you could use a collision callback that determines when the ball is 'in' the sand (colliding with the bunker geom) and then apply some forces to slow it to a stop (friction callback comes to mind, check the examples).

Recently i played around with physics a bit and stumbled about an easy way to apply forces in a limited area.

Just create a BoundingBox (or use the bounds of an existing object like your bunker).

Test if the ball intersects with the BoundingBox and apply or remove forces if its inside.

That way you can for example apply a high friction if the ball is inside the bunker.

In the following example, 'target' could be your golf ball, and 'area' the bunker.

Just don't addforce() like i did

``` public class SimpleAreaInfluence implements PhysicsUpdateCallback {    private DynamicPhysicsNode target;    private Vector3f direction;    private float force;    private Spatial area;    public SimpleAreaInfluence(DynamicPhysicsNode target, Vector3f direction, float force, Spatial area) {       this.target = target;       this.direction = direction;       this.force = force;       this.area = area;    }        public void afterStep(PhysicsSpace space, float time) {       if (target.getWorldBound().intersects(area.getWorldBound())) {          target.addForce(direction.mult(force));       }    }    public void beforeStep(PhysicsSpace space, float time) {    } } ```

thank you both for your help! I will be a little busy during the weekend due to exams, I will be testing what you suggested next wednesday and let you know if everything went fine!!

thanks again