Skip to content

D. Making a 3D Cube with Entity

Estimated time: 7 minutes | Previous: C. Declaring Variables | Next: E. Final Code and Running It


๐ŸŽฏ Learning Goals

By the end of this lesson, you'll be able to:

  • โ—‹ Entity()can create 3D objects with
  • โ—‹ model, color, scale can use arguments
  • โ—‹ can store an Entity in a variable

Core Concepts

What Is Entity?

Entityrepresents every object in the game world in Ursina.

๐Ÿ“ Analogy: LEGO blocks

An Entity is a LEGO blockis the same!

  • Comes in various shapes (cube, sphere, plane)
  • Can be painted a color
  • Can be resized
  • Can be combined to build complex things

An Entity is the basic building block of the game world!

Entity Creation Flowchart

flowchart TD
    A["Entity()"] --> B{"Set arguments"}
    B --> C["model='cube'<br/>Sets the shape"]
    B --> D["color=color.red<br/>Sets the color"]
    B --> E["scale=2<br/>Sets the size"]
    C --> F["3D object created!"]
    D --> F
    E --> F

    style A fill:#e3f2fd,stroke:#1976d2
    style F fill:#e8f5e9,stroke:#388e3c

Creating an Entity

my_cube = Entity(
    model='cube',
    color=color.red,
    scale=2
)

Argument descriptions:

  • model='cube': cube shape
  • color=color.red: red
  • scale=2: 2x size

Key Arguments

Argument Role Example value
model Shape 'cube', 'sphere', 'plane'
color Color color.red, color.blue, color.green
scale Size 1, 2, (2,1,3)
position Position (0,0,0), (1,2,3)

Available shapes

model value Shape Description
'cube' Cube The most basic 3D shape
'sphere' Sphere A round ball shape
'plane' Plane A flat floor panel
'quad' Square A 2D rectangle

โš ๏ธ Watch the argument format!

Arguments are name=value written in this format!

  • โœ… model='cube' (use an equals sign)
  • โŒ model:'cube' (no colons allowed)
  • โŒ model-'cube' (no hyphens allowed)

Example Code

from ursina import *

app = Ursina()

# Store the settings in variables
cube_color = color.red
cube_size = 2

# Make a cube with Entity
my_cube = Entity(
    model='cube',
    color=cube_color,
    scale=cube_size
)

app.run()

Result

A red cube appears in the center of the screen!

  • Size: 2x the default
  • Color: red
  • Position: center of the screen (0, 0, 0)

๐ŸŽฏ Quiz

Quiz: Entity arguments
Which argument sets an Entity's shape?
Show Answer

Answer: A) model

  • model: sets the shape (cube, sphere, etc.)
  • color: sets the color (red, blue, etc.)
  • scale: sets the size (1, 2, etc.)

๐Ÿ”ง Debug Clinic

Problem: TypeError: Entity() got an unexpected keyword argument

Cause: a typo in the argument name

Fix: use the exact argument name

# โŒ Wrong code
Entity(modle='cube')  # model typo!
Entity(colour=color.red)  # color typo!
# โœ… Correct code
Entity(model='cube')  # Correct name!
Entity(color=color.red)

Problem: I can't see the cube!

Cause: a camera position or cube size issue

Fix: check the scale value or add EditorCamera

# โœ… Explore 3D space with EditorCamera
from ursina import *
app = Ursina()

Entity(model='cube', color=color.red)
EditorCamera()  # You can adjust the view with the mouse!

app.run()

Try Coding It Yourself

Try making different Entities!

Creating a Blue Sphere

Write the code to make a blue sphere.

Example Answer
from ursina import *

app = Ursina()

my_sphere = Entity(
    model='sphere',
    color=color.blue
)

app.run()

Result: A blue sphere appears in the center of the screen!


๐Ÿงฉ Key Takeaways

What you learned in this lesson:

  • Entity: every object in the game world (LEGO blocks)
  • model: sets the shape ('cube', 'sphere' etc.)
  • color: sets the color (color.red etc.)
  • scale: sets the size (a number)
  • Argument format: name=value (use an equals sign!)

Review Checklist

  • [ ] Can you explain what an Entity is?
  • [ ] Do you know what the model, color, and scale arguments do?
  • [ ] Do you know how to store an Entity in a variable?

Next step: E. Final Code and Running It โ†’