5 minutes
Right now your capsule walks straight through walls, and there is nothing to kick. The mover snaps the mesh to whatever spot the math picks. The walls are only painted boxes.
One component fixes both problems. It is called Physics. But it also changes how Movement works. That second change is what this lesson is about.
Add physics bodies and a ball
Give the ground and the four walls a static body. A static body never moves and has infinite mass. Give the player a dynamic capsule, which falls and collides. Then add the ball as a dynamic sphere:
Add the same static Physics block to Wall_S, Wall_E, and Wall_W. Two fields do most of the work here: shapeType and motionType:
static bodies never move. They also ignore every collision. That makes them perfect for the pitch and the walls. dynamic bodies follow gravity, mass, and impact. Those are the player and the ball. lockRotation: true keeps the capsule standing upright, so it will not tip over. Under Babylon, all of this runs through Havok. On the ball, restitution: 0.6 sets how much it bounces. friction: 0.4 sets how fast it loses speed on the grass.
Continue reading
Unlock the Full Course
Every lesson, the runnable examples, and the finished build — yours to keep.