0
votes

My use-case is to let a ball bounce and come towards the camera (been able to do that with a simple dynamic-body sphere on a static-body grid). However, rather than it rolling down to a position where it loses its velocity (or momentum), is there a way to stop it at a desired point? I tried placing a (invisible) hurdle object but it rolls back. I would like it to remain stationary once it reaches the desired point. Thanks

1

1 Answers

0
votes

You can stop the dynamic-body by zeroing a few body attributes

 let body = el.body // el = aframe entity
 body.velocity.set(0,0,0);
 body.angularVelocity.set(0,0,0);
 body.vlambda.set(0,0,0);
 body.wlambda.set(0,0,0);

Working example here.


However IF your ball is on a slope, the physics engine will, properly, slowly accelerate it.

If you want it to stop no matter what (defying the laws of CANNON.js physics), then either remove the dynamic-body component, or swap it with a static-body.