Creating 3D Planets in Godot

Jul 12, 2024

Lecture Notes: Creating 3D Planets in Godot

Overview

  • Topic: Level design in Super Mario Galaxy and a tutorial for creating similar 3D planets in Godot.
  • Key Mechanics: Walking around planets, gravitational attraction between planets, and character movement.

Mechanics Breakdown

  1. Gravitational Attraction
  2. Character Movement

Setting Up Planets

  • Use Godot's powerful physics options.
  • Essential nodes:
    • StaticBody: Walkable surface
    • Area: Handles gravitational attraction

Steps to Create a Planet

  1. StaticBody Node
    • Add a spherical MeshInstance
    • Add a matching sphere CollisionShape
  2. Area Node
    • Add a sphere CollisionShape larger than the planet for gravity
    • Enable gravity point
    • Set gravity_vec to (0, 0, 0)
    • Change space override to replace
    • Adjust gravity strength

Scene Setup

  • Add two planets with overlapping gravity areas for inter-planet jumps.
  • Position a camera to capture both planets.

Character Setup

  • Use a RigidBody for the character to leverage Godot's physics.
  • Add capsule CollisionShape and mesh for the character's body.
  • Enable character mode to keep the character upright.
  • Enable contact monitor and set contacts_reported to at least 1.

Player Controls and Orientation

  1. Controls Relative to Character
  2. Orientation to the Planet
  • All movement handled in _integrate_forces()
  • Calculate player’s input direction
  • Use xform function to align character’s move direction
  • Move character using add_force
  • Align model with movement using Basis
  • Calculate third vector with vector cross product
  • Use spherical lerp for smooth turning

Implementing Jumping Mechanic

  • Use contact monitoring to check if character is on the floor
  • Loop through contact points and normals every frame
  • Use dot product to compare angle of vectors
  • If dot product > 0.5, assume character is on the floor
  • Apply impulse in the opposite direction of gravity when jumping

Additional Information

  • Promotion for Learn to Code from Zero, with Godot on Kickstarter.
  • Free, open-source app in development to learn Godot’s GDScript in browser.
  • Campaign details and deadline: until October 31.

Action Items

  • Check out the Kickstarter campaign for early access and support the development of the learning platform.