Create the Ball
In the editor:
- Create a GameObject named
Ball. - Add
SphereRendererso you can see it. - Add
SphereCollider3Dso physics has a shape to test. - Add
Rigidbody3Dso physics can move it. - Press Play.
With gravity enabled on the Rigidbody, the ball should fall.
If it does not fall, check that the Rigidbody is enabled and its body type is Dynamic.
Add a Floor
Now create something for the ball to land on.
In the editor:
- Create a GameObject named
Ground. - Add a visible renderer such as
CubeRenderer. - Scale it into a flat platform.
- Add
BoxCollider3D. - Leave it without a Rigidbody, or add
Rigidbody3Dwith body type set toStatic. - Press Play again.
The ball should now fall until it reaches the floor collider.
This is the basic 3D physics authoring loop: visible renderer, collider shape, then Rigidbody when the object itself should move.
Choose the Body Type
Rigidbody3D supports three body types:
Dynamic: physics moves the object with gravity, velocity, and forces.Kinematic: gameplay code moves the object, while physics can still test it against other bodies.Static: the object is treated as non-moving level geometry.
Start with Dynamic for things that should fall, roll, bounce, or be pushed.
Use Static for walls, floors, ramps, and scenery.
Use Kinematic when you need scripted motion, such as a moving platform or a door that follows an animation.
Add a Simple Launch Script
Once the object falls and collides correctly, add a small script that applies an impulse.
<?php
declare(strict_types=1);
namespace Game\Scripts;
use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\Input;
use Lenga\Engine\Core\Rigidbody3D;
use Lenga\Engine\Core\Vector3;
use Lenga\Engine\Enumerations\ForceMode;
use Lenga\Engine\Enumerations\KeyCode;
final class BallLauncher extends Behaviour
{
public float $launchForce = 8.0;
private ?Rigidbody3D $body = null;
public function start(): void
{
$this->body = $this->getComponent(Rigidbody3D::class);
}
public function update(): void
{
if (!$this->body instanceof Rigidbody3D || !Input::getKeyDown(KeyCode::SPACE)) {
return;
}
$this->body->addForce(new Vector3(0.0, $this->launchForce, 0.0), ForceMode::Impulse);
}
}
Attach this Behaviour to the same GameObject as the Rigidbody3D.
When you press Space, the Rigidbody receives one upward impulse.
Tip: Fast Bodies
If a fast body passes through thin colliders, set its Rigidbody collision detection to Continuous.