Tutorials / How to

✔ OfficialBeginner⏱ 15 minTallow 0.1 and 0.2

Make things fall and collide

Tallow's physics uses Jolt. Two components do most of the work:

  • A collider (Box, Sphere, Capsule, Mesh or Convex) gives an object a shape. On its own it makes the object fixed scenery.
  • A Rigidbody makes an object move under gravity and collisions. It needs a collider on the same object.

Step 1: Make a floor

  1. GameObject > 3D Object > Cube, and rename it Floor (F2).
  2. Set its Scale to 20, 1, 20 and its Position to 0, -0.5, 0.
  3. Add Component > Box Collider. The default size of 1, 1, 1 fits the cube, and it is scaled along with it.

The floor has a collider but no Rigidbody, so it stays put.

Step 2: Drop a box

  1. Add another cube and move it up to 0, 5, 0.
  2. Add a Box Collider, then a Rigidbody.

Press Play. The box falls and lands on the floor.

Step 3: Try the Rigidbody's settings

Stop, select the box and change some of these, then play again:

Field Effect
Mass How heavy it is, in kilograms. Heavy things push light ones.
Bounciness 0 lands dead. Near 1 bounces almost back to where it started.
Friction How much it grips while sliding.
Gravity Scale 0 floats. 2 falls twice as fast.
Is Kinematic Moved by your scripts only, but still pushes other bodies.
Freeze Rotation Never tips over.

Turn the box a little (E, or Rotation 30, 0, 20) before playing to see it tumble.

Step 4: Add a ball and a pile

  1. GameObject > 3D Object > Sphere at 0.3, 8, 0, with a Sphere Collider and a Rigidbody. Set Bounciness to 0.7.
  2. Select the box and press Ctrl+D a few times, moving each copy up a little, to stack a tower.

Play. The ball drops onto the tower.

Step 5: Push things from a script

Create a script called Launcher (Project panel, Script > Basic Component) that throws its object upward when you press Space:

using System;
using Tallow;

namespace MyFirstGame;

[Component]
class Launcher : Script
{
    public float strength = 8;

    public override void Update(TickInput input, float deltaTime)
    {
        if (!input.Pressed(.Jump))
            return;
        let body = GetComponent<Rigidbody>();
        if (body)                    // true when the object has a Rigidbody
            body.AddImpulse(.(0, strength, 0));
    }
}

In 0.2, engine components such as Rigidbody, Camera and CharacterController are handles: small values that point at the component's data. Check one with if (body), not body != null.

Add Launcher to the ball and play. Each press of Space throws it up. AddImpulse gives an instant kick. AddForce pushes steadily, every update you call it.

On 0.1: derive from Component, use public override void Update(), check Input.GetKeyDown(.Space), and test the body with body != null.

Step 6: Where next