Back to Docs

⚙️ Physics Engine

Add realistic physics simulation to your games with gravity, collisions, forces, and constraints

🌍 Physics Overview

The Vigthoria Game Engine uses a powerful physics simulation system that handles gravity, collisions, forces, and constraints. Physics runs in real-time during Play mode, allowing realistic object interactions.

⚡ Performance

Physics simulation runs on the GPU when available, supporting hundreds of dynamic objects at 60+ FPS on modern hardware.

🔧 Core Components

Rigidbody

Makes an object respond to physics forces like gravity, collisions, and impulses. Required for any object that should move based on physics.

  • Mass float (kg)
  • Drag float (air resistance)
  • Angular Drag float (rotation resistance)
  • Use Gravity boolean
  • Is Kinematic boolean (controlled by script)
  • Freeze Position X, Y, Z axis locks
  • Freeze Rotation X, Y, Z axis locks

Collider

Defines the physical shape used for collision detection. An object needs a collider to interact with other physical objects.

Collider Types:
Box

Fast, simple rectangular

Sphere

Fastest, perfect for balls

Capsule

Ideal for characters

Mesh

Exact shape, slowest

Constraints

Connect objects together with physical joints that limit movement in specific ways.

  • Fixed Joint Locks objects together
  • Hinge Joint Rotates around one axis (doors)
  • Spring Joint Elastic connection
  • Slider Joint Movement along one axis
  • Ball Joint Rotates freely (ragdoll)

📝 Adding Physics

Step 1: Add a Rigidbody

Select your object → Inspector → Add Component → Physics → Rigidbody

Step 2: Add a Collider

Select your object → Inspector → Add Component → Physics → [Collider Type]

💡 Auto-Fit Colliders

Click "Fit to Mesh" in the collider settings to automatically size the collider to match your object's mesh bounds.

Step 3: Configure Properties

Adjust mass, drag, and constraints based on how you want the object to behave.

🎮 Common Physics Setups

Player Character

  • Collider Capsule
  • Rigidbody Freeze Rotation X, Y, Z
  • Mass 70-80 kg

Pushable Crate

  • Collider Box
  • Rigidbody Default settings
  • Mass 20-50 kg

Swinging Door

  • Collider Box
  • Joint Hinge Joint (on edge)
  • Rigidbody Use Gravity: false

Bouncing Ball

  • Collider Sphere
  • Rigidbody Low Drag
  • Physics Material Bounciness: 0.8

💻 Scripting Physics

Control physics through code for custom game mechanics:

// Apply force to move an object
rigidbody.AddForce(Vector3.forward * 10);

// Apply impulse (instant velocity change)
rigidbody.AddImpulse(Vector3.up * 5);

// Set velocity directly
rigidbody.velocity = new Vector3(0, 10, 0);

// Detect collisions
function onCollisionEnter(collision) {
  console.log("Hit: " + collision.gameObject.name);
}

⚠️ Performance Tips