Skip to content

Commit

Permalink
Merge pull request #421 from aaronfranke/platform-3d-animtree
Browse files Browse the repository at this point in the history
Update Platformer 3D to use AnimationTree and organize into subfolders
  • Loading branch information
aaronfranke authored Feb 20, 2020
2 parents 001e51d + 399de3e commit de8a79b
Show file tree
Hide file tree
Showing 49 changed files with 461 additions and 516 deletions.
2 changes: 1 addition & 1 deletion 3d/platformer/coin.gd → 3d/platformer/coin/coin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ extends Area
var taken = false

func _on_coin_body_enter(body):
if not taken and body is preload("res://player.gd"):
if not taken and body is preload("res://player/player.gd"):
get_node("Animation").play("take")
taken = true
6 changes: 3 additions & 3 deletions 3d/platformer/coin.tscn → 3d/platformer/coin/coin.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[gd_scene load_steps=14 format=2]

[ext_resource path="res://coin.gd" type="Script" id=1]
[ext_resource path="res://sound_coin.wav" type="AudioStream" id=2]
[ext_resource path="res://shine.png" type="Texture" id=3]
[ext_resource path="res://coin/coin.gd" type="Script" id=1]
[ext_resource path="res://coin/sound_coin.wav" type="AudioStream" id=2]
[ext_resource path="res://enemy/shine.png" type="Texture" id=3]

[sub_resource type="SpatialMaterial" id=1]
albedo_color = Color( 1, 0.837686, 0, 1 )
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

importer="wav"
type="AudioStreamSample"
path="res://.import/sound_coin.wav-b4defacd1a1eab95585c7b5095506878.sample"
path="res://.import/sound_coin.wav-5f523c825e94d407ed9e355cbe69ab46.sample"

[deps]

source_file="res://sound_coin.wav"
dest_files=[ "res://.import/sound_coin.wav-b4defacd1a1eab95585c7b5095506878.sample" ]
source_file="res://coin/sound_coin.wav"
dest_files=[ "res://.import/sound_coin.wav-5f523c825e94d407ed9e355cbe69ab46.sample" ]

[params]

Expand Down
Binary file removed 3d/platformer/cutout.png
Binary file not shown.
34 changes: 0 additions & 34 deletions 3d/platformer/cutout.png.import

This file was deleted.

2 changes: 1 addition & 1 deletion 3d/platformer/enemy.gd → 3d/platformer/enemy/enemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func _integrate_forces(state):
var dp = state.get_contact_local_normal(i)

if cc:
if cc is preload("res://bullet.gd") and cc.enabled:
if cc is preload("res://player/bullet/bullet.gd") and cc.enabled:
set_mode(MODE_RIGID)
dying = true
state.set_angular_velocity(-dp.cross(up).normalized() * 33.0)
Expand Down
10 changes: 5 additions & 5 deletions 3d/platformer/enemy.tscn → 3d/platformer/enemy/enemy.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[gd_scene load_steps=25 format=2]

[ext_resource path="res://enemy.gd" type="Script" id=1]
[ext_resource path="res://robot_walk.wav" type="AudioStream" id=2]
[ext_resource path="res://sound_hit.wav" type="AudioStream" id=3]
[ext_resource path="res://sound_explode.wav" type="AudioStream" id=4]
[ext_resource path="res://shine.png" type="Texture" id=5]
[ext_resource path="res://enemy/enemy.gd" type="Script" id=1]
[ext_resource path="res://enemy/robot_walk.wav" type="AudioStream" id=2]
[ext_resource path="res://enemy/sound_hit.wav" type="AudioStream" id=3]
[ext_resource path="res://enemy/sound_explode.wav" type="AudioStream" id=4]
[ext_resource path="res://enemy/shine.png" type="Texture" id=5]

[sub_resource type="PhysicsMaterial" id=1]
friction = 0.0
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

importer="wav"
type="AudioStreamSample"
path="res://.import/robot_walk.wav-4313e7d5f563e62e3923080b14a79c15.sample"
path="res://.import/robot_walk.wav-e477aac8926497af29eed244f64833e8.sample"

[deps]

source_file="res://robot_walk.wav"
dest_files=[ "res://.import/robot_walk.wav-4313e7d5f563e62e3923080b14a79c15.sample" ]
source_file="res://enemy/robot_walk.wav"
dest_files=[ "res://.import/robot_walk.wav-e477aac8926497af29eed244f64833e8.sample" ]

[params]

Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

importer="texture"
type="StreamTexture"
path.s3tc="res://.import/shine.png-a8253c1d2dc8acbf187823f695c13207.s3tc.stex"
path.etc2="res://.import/shine.png-a8253c1d2dc8acbf187823f695c13207.etc2.stex"
path.s3tc="res://.import/shine.png-4170bd0cee6f5d251a3f551d4acf3e6c.s3tc.stex"
path.etc2="res://.import/shine.png-4170bd0cee6f5d251a3f551d4acf3e6c.etc2.stex"
metadata={
"imported_formats": [ "s3tc", "etc2" ],
"vram_texture": true
}

[deps]

source_file="res://shine.png"
dest_files=[ "res://.import/shine.png-a8253c1d2dc8acbf187823f695c13207.s3tc.stex", "res://.import/shine.png-a8253c1d2dc8acbf187823f695c13207.etc2.stex" ]
source_file="res://enemy/shine.png"
dest_files=[ "res://.import/shine.png-4170bd0cee6f5d251a3f551d4acf3e6c.s3tc.stex", "res://.import/shine.png-4170bd0cee6f5d251a3f551d4acf3e6c.etc2.stex" ]

[params]

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

importer="wav"
type="AudioStreamSample"
path="res://.import/sound_explode.wav-23e94be75a4346bffb517c7e07035977.sample"
path="res://.import/sound_explode.wav-38875bfce76147e228902e26b716f579.sample"

[deps]

source_file="res://sound_explode.wav"
dest_files=[ "res://.import/sound_explode.wav-23e94be75a4346bffb517c7e07035977.sample" ]
source_file="res://enemy/sound_explode.wav"
dest_files=[ "res://.import/sound_explode.wav-38875bfce76147e228902e26b716f579.sample" ]

[params]

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

importer="wav"
type="AudioStreamSample"
path="res://.import/sound_hit.wav-d8455980ada2d4a9a73508948d7317cc.sample"
path="res://.import/sound_hit.wav-954732368f39d5a47e196d428c1ff53a.sample"

[deps]

source_file="res://sound_hit.wav"
dest_files=[ "res://.import/sound_hit.wav-d8455980ada2d4a9a73508948d7317cc.sample" ]
source_file="res://enemy/sound_hit.wav"
dest_files=[ "res://.import/sound_hit.wav-954732368f39d5a47e196d428c1ff53a.sample" ]

[params]

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=10 format=2]

[ext_resource path="res://bullet.gd" type="Script" id=1]
[ext_resource path="res://player/bullet/bullet.gd" type="Script" id=1]

[sub_resource type="SpatialMaterial" id=1]
flags_transparent = true
Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

importer="texture"
type="StreamTexture"
path="res://.import/osb_down.png-4a1ab934f787719766862b499528d054.stex"
path="res://.import/osb_down.png-3bcabfc1fcfaeeccc61e2e829d6554c4.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://osb_down.png"
dest_files=[ "res://.import/osb_down.png-4a1ab934f787719766862b499528d054.stex" ]
source_file="res://player/controls/osb_down.png"
dest_files=[ "res://.import/osb_down.png-3bcabfc1fcfaeeccc61e2e829d6554c4.stex" ]

[params]

Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

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

[deps]

source_file="res://osb_fire.png"
dest_files=[ "res://.import/osb_fire.png-e657a73546eb75918e9d9a3fea15cf70.stex" ]
source_file="res://player/controls/osb_fire.png"
dest_files=[ "res://.import/osb_fire.png-2e93a3da4bfeb57477fca7905c0173a4.stex" ]

[params]

Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

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

[deps]

source_file="res://osb_jump.png"
dest_files=[ "res://.import/osb_jump.png-dbbef3b47abbb562ce6c81a9701121c6.stex" ]
source_file="res://player/controls/osb_jump.png"
dest_files=[ "res://.import/osb_jump.png-aa75300abbd0a7d9e9bc4796371c64a3.stex" ]

[params]

Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

importer="texture"
type="StreamTexture"
path="res://.import/osb_left.png-fc7230aeb0eec74933ed08f89b893288.stex"
path="res://.import/osb_left.png-10e92e56ebe36a5205968909dc4b286b.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://osb_left.png"
dest_files=[ "res://.import/osb_left.png-fc7230aeb0eec74933ed08f89b893288.stex" ]
source_file="res://player/controls/osb_left.png"
dest_files=[ "res://.import/osb_left.png-10e92e56ebe36a5205968909dc4b286b.stex" ]

[params]

Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

importer="texture"
type="StreamTexture"
path="res://.import/osb_right.png-5cf5add2dbc1c8dde17173ac56f3a004.stex"
path="res://.import/osb_right.png-fb8adc0d65f2da35441a371b0865044c.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://osb_right.png"
dest_files=[ "res://.import/osb_right.png-5cf5add2dbc1c8dde17173ac56f3a004.stex" ]
source_file="res://player/controls/osb_right.png"
dest_files=[ "res://.import/osb_right.png-fb8adc0d65f2da35441a371b0865044c.stex" ]

[params]

Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

importer="texture"
type="StreamTexture"
path="res://.import/osb_up.png-6a05b6a7bf0ede3756308a5cffdd2b9a.stex"
path="res://.import/osb_up.png-03a826da4884734d6f66c813539bfce8.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://osb_up.png"
dest_files=[ "res://.import/osb_up.png-6a05b6a7bf0ede3756308a5cffdd2b9a.stex" ]
source_file="res://player/controls/osb_up.png"
dest_files=[ "res://.import/osb_up.png-03a826da4884734d6f66c813539bfce8.stex" ]

[params]

Expand Down
File renamed without changes.
29 changes: 11 additions & 18 deletions 3d/platformer/player.gd → 3d/platformer/player/player.gd
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
extends KinematicBody

const ANIM_FLOOR = 0
const ANIM_AIR_UP = 1
const ANIM_AIR_DOWN = 2
const ANIM_AIR = 1

const SHOOT_TIME = 1.5
const SHOOT_SCALE = 2
const CHAR_SCALE = Vector3(0.3, 0.3, 0.3)
const TURN_SPEED = 40

var facing_dir = Vector3.RIGHT
var movement_dir = Vector3()
var linear_velocity = Vector3()

Expand All @@ -27,7 +25,7 @@ var shoot_blend = 0
onready var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") * ProjectSettings.get_setting("physics/3d/default_gravity_vector")

func _ready():
get_node("AnimationTreePlayer").set_active(true)
get_node("AnimationTree").set_active(true)


func _physics_process(delta):
Expand All @@ -41,13 +39,11 @@ func _physics_process(delta):
var hdir = hv.normalized() # Horizontal direction.
var hspeed = hv.length() # Horizontal speed.

# Player input
# Player input.
var cam_basis = get_node("Target/Camera").get_global_transform().basis
var dir = Vector3() # Where does the player intend to walk to.
dir = Input.get_action_strength("move_right") * cam_basis[0]
dir -= Input.get_action_strength("move_left") * cam_basis[0]
dir += Input.get_action_strength("move_backwards") * cam_basis[2]
dir -= Input.get_action_strength("move_forward") * cam_basis[2]
dir = (Input.get_action_strength("move_right") - Input.get_action_strength("move_left")) * cam_basis[0]
dir += (Input.get_action_strength("move_backwards") - Input.get_action_strength("move_forward")) * cam_basis[2]
dir.y = 0
dir = dir.normalized()

Expand All @@ -60,7 +56,6 @@ func _physics_process(delta):
if dir.length() > 0.1 and !sharp_turn:
if hspeed > 0.001:
hdir = adjust_facing(hdir, dir, delta, 1.0 / hspeed * TURN_SPEED, Vector3.UP)
facing_dir = hdir
else:
hdir = dir

Expand Down Expand Up @@ -88,10 +83,7 @@ func _physics_process(delta):
jumping = true
get_node("SoundJump").play()
else:
if vv > 0:
anim = ANIM_AIR_UP
else:
anim = ANIM_AIR_DOWN
anim = ANIM_AIR

if dir.length() > 0.1:
hv += dir * (accel * 0.2 * delta)
Expand Down Expand Up @@ -121,7 +113,7 @@ func _physics_process(delta):

if shoot_attempt and not prev_shoot:
shoot_blend = SHOOT_TIME
var bullet = preload("res://bullet.tscn").instance()
var bullet = preload("res://player/bullet/bullet.tscn").instance()
bullet.set_transform(get_node("Armature/Bullet").get_global_transform().orthonormalized())
get_parent().add_child(bullet)
bullet.set_linear_velocity(get_node("Armature/Bullet").get_global_transform().basis[2].normalized() * 20)
Expand All @@ -131,10 +123,11 @@ func _physics_process(delta):
prev_shoot = shoot_attempt

if is_on_floor():
get_node("AnimationTreePlayer").blend2_node_set_amount("walk", hspeed / max_speed)
$AnimationTree["parameters/walk/blend_amount"] = hspeed / max_speed

get_node("AnimationTreePlayer").transition_node_set_current("state", anim)
get_node("AnimationTreePlayer").blend2_node_set_amount("gun", min(shoot_blend, 1.0))
$AnimationTree["parameters/state/current"] = anim
$AnimationTree["parameters/air_dir/blend_amount"] = clamp(-linear_velocity.y / 4 + 0.5, 0, 1)
$AnimationTree["parameters/gun/blend_amount"] = min(shoot_blend, 1.0)


func adjust_facing(p_facing, p_target, p_step, p_adjust_rate, current_gn):
Expand Down
Loading

0 comments on commit de8a79b

Please sign in to comment.