Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 2.5D Demo Projects #315

Merged
merged 7 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Lines starting with '#' are comments.
# Each line is a file pattern followed by one or more owners.
# Owners can be @users, @org/teams or emails

/misc/2.5d @aaronfranke
/mono/2.5d @aaronfranke
35 changes: 35 additions & 0 deletions misc/2.5d/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 2.5D Demo Project (GDScript)

This demo project shows a way to create a 2.5D game in Godot by mixing 2D and 3D nodes. It also adds a 2.5D editor viewport for easily editing 2.5D levels.

Note: There is a Mono C# version available [here](https://github.com/godotengine/godot-demo-projects/tree/master/mono/2.5d).

## How does it work?

Custom node types are added in a Godot plugin to allow 2.5D objects. Node25D serves as the base for all 2.5D objects. Its first child must be a 3D Spatial, which is used to calculate its position. Then, add a 2D Sprite (or similar) to display the object.

Inside of Node25D, a 2.5D transformation matrix made of three Vector2 is used to calculate the 2D position from the 3D position. For getting a 3D position, this project uses KinematicBody and StaticBody (3D), but these only exist for math - the camera is 2D and all sprites are 2D. You are able to use any Spatial node for math.

Several view modes are implemented, including top down, front side, 45 degree, isometric, and two oblique modes. To implement a different view angle, all you need to do is create a new set of basis vectors in Node25D, use it on all instances, and of course create sprites to display that object in 2D.

The plugin also adds YSort25D to sort Node25D nodes, and ShadowMath25D for calculating a shadow (a simple KinematicBody that tries to cast downward).

## Screenshots

![Forty Five Degrees](screenshots/forty_five.png)

![Isometric](screenshots/isometric.png)

![Oblique Z](screenshots/oblique_z.png)

![Oblique Y](screenshots/oblique_y.png)

![Front Side](screenshots/front_side.png)

![Cube](screenshots/cube.png)

![2.5D Editor Viewport](screenshots/editor.png)

## Music License

`assets/mr_mrs_robot.ogg` Copyright © circa 2008 Juan Linietsky, CC-BY: Attribution.
52 changes: 52 additions & 0 deletions misc/2.5d/addons/node25d/.broken-gdscripts/Basis25D.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Currently broken unless Godot makes this kind of thing possible:
# https://github.com/godotengine/godot/issues/21461
# https://github.com/godotengine/godot-proposals/issues/279

# Basis25D structure for performing 2.5D transform math.
# Note: All code assumes that Y is UP in 3D, and DOWN in 2D.
# Meaning, a top-down view has a Y axis component of (0, 0), with a Z axis component of (0, 1).
# For a front side view, Y is (0, -1) and Z is (0, 0).
# Remember that Godot's 2D mode has the Y axis pointing DOWN on the screen.

class_name Basis25D

var x: Vector2 = Vector2()
var y: Vector2 = Vector2()
var z: Vector2 = Vector2()

static func top_down():
return init(1, 0, 0, 0, 0, 1)

static func front_side():
return init(1, 0, 0, -1, 0, 0)

static func forty_five():
return init(1, 0, 0, -0.70710678118, 0, 0.70710678118)

static func isometric():
return init(0.86602540378, 0.5, 0, -1, -0.86602540378, 0.5)

static func oblique_y():
return init(1, 0, -1, -1, 0, 1)

static func oblique_z():
return init(1, 0, 0, -1, -1, 1)

# Creates a Dimetric Basis25D from the angle between the Y axis and the others.
# Dimetric(2.09439510239) is the same as Isometric.
# Try to keep this number away from a multiple of Tau/4 (or Pi/2) radians.
static func dimetric(angle):
var sine = sin(angle)
var cosine = cos(angle)
return init(sine, -cosine, 0, -1, -sine, -cosine)

static func init(xx, xy, yx, yy, zx, zy):
var xv = Vector2(xx, xy)
var yv = Vector2(yx, yy)
var zv = Vector2(zx, zy)
return Basis25D.new(xv, yv, zv)

func _init(xAxis: Vector2, yAxis: Vector2, zAxis: Vector2):
x = xAxis
y = yAxis
z = zAxis
22 changes: 22 additions & 0 deletions misc/2.5d/addons/node25d/.broken-gdscripts/Transform25D.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Currently broken unless Godot makes this kind of thing possible:
# https://github.com/godotengine/godot/issues/21461
# https://github.com/godotengine/godot-proposals/issues/279

# Calculates the 2D transformation from a 3D position and a Basis25D.

class_name Transform25D

var spatial_position: Vector3 = Vector3()
var basis #: Basis25D

func flat_transform():
return Transform2D(0, flat_position())

func flat_position():
var pos = spatial_position.x * basis.x
pos += spatial_position.y * basis.y
pos += spatial_position.z * basis.z
return pos

func _init(basis25d):
basis = basis25d
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions misc/2.5d/addons/node25d/icons/kinematic_body_25d.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/kinematic_body_25d.png-c455d5ccb8ec7543b62fff6e803eee7c.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/node25d/icons/kinematic_body_25d.png"
dest_files=[ "res://.import/kinematic_body_25d.png-c455d5ccb8ec7543b62fff6e803eee7c.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added misc/2.5d/addons/node25d/icons/node_25d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions misc/2.5d/addons/node25d/icons/node_25d.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/node_25d.png-72e45d8600ccbde01c6d9ad51f5fc530.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/node25d/icons/node_25d.png"
dest_files=[ "res://.import/node_25d.png-72e45d8600ccbde01c6d9ad51f5fc530.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added misc/2.5d/addons/node25d/icons/node_25d_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions misc/2.5d/addons/node25d/icons/node_25d_icon.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/node_25d_icon.png-2ad780313818706789bbb15408797db2.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/node25d/icons/node_25d_icon.png"
dest_files=[ "res://.import/node_25d_icon.png-2ad780313818706789bbb15408797db2.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions misc/2.5d/addons/node25d/icons/shadow_math_25d.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/shadow_math_25d.png-333790a3285ee4c26792088985815eba.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/node25d/icons/shadow_math_25d.png"
dest_files=[ "res://.import/shadow_math_25d.png-333790a3285ee4c26792088985815eba.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions misc/2.5d/addons/node25d/icons/shadow_math_25d_icon.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/shadow_math_25d_icon.png-f286bd905218b9a04121a430c1fdd042.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/node25d/icons/shadow_math_25d_icon.png"
dest_files=[ "res://.import/shadow_math_25d_icon.png-f286bd905218b9a04121a430c1fdd042.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
1 change: 1 addition & 0 deletions misc/2.5d/addons/node25d/icons/viewport_25d.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions misc/2.5d/addons/node25d/icons/viewport_25d.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/viewport_25d.svg-5df077fb699779f821141e20086cbf11.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/node25d/icons/viewport_25d.svg"
dest_files=[ "res://.import/viewport_25d.svg-5df077fb699779f821141e20086cbf11.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added misc/2.5d/addons/node25d/icons/y_sort_25d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions misc/2.5d/addons/node25d/icons/y_sort_25d.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/y_sort_25d.png-2e15f3765afd8b0136201cb9dea4049b.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/node25d/icons/y_sort_25d.png"
dest_files=[ "res://.import/y_sort_25d.png-2e15f3765afd8b0136201cb9dea4049b.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added misc/2.5d/addons/node25d/icons/y_sort_25d_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading