Skip to content

Commit e09ec97

Browse files
committed
Add 3D physics interpolation demo
Demonstrate first person shooter and third person shooter cameras.
1 parent 0d6b772 commit e09ec97

File tree

15 files changed

+662
-0
lines changed

15 files changed

+662
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[gd_scene load_steps=4 format=3 uid="uid://cvgxw8nq67xxm"]
2+
3+
[sub_resource type="BoxShape3D" id="BoxShape3D_pq8q7"]
4+
5+
[sub_resource type="BoxMesh" id="BoxMesh_pyidc"]
6+
7+
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_oq5cr"]
8+
albedo_color = Color(0.5544661, 0.39379695, 0.15444939, 1)
9+
10+
[node name="Box" type="RigidBody3D"]
11+
mass = 10.0
12+
13+
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
14+
shape = SubResource("BoxShape3D_pq8q7")
15+
16+
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
17+
mesh = SubResource("BoxMesh_pyidc")
18+
surface_material_override/0 = SubResource("StandardMaterial3D_oq5cr")
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
extends RigidBody3D
2+
3+
# How many ticks the bullet should last for.
4+
const _max_life = 100
5+
6+
# Scale the bullet in over a tick so it doesn't appear out of nowhere.
7+
const _appearance_life = 1
8+
9+
# The current lifetime tick of the bullet.
10+
var _life = 0
11+
12+
var _enabled = false
13+
14+
func _ready() -> void:
15+
$CollisionShape3D.disabled = true
16+
17+
func _physics_process(_delta: float) -> void:
18+
# Start with physics collision disabled until the first tick.
19+
if !_enabled:
20+
$CollisionShape3D.disabled = false
21+
_enabled = true
22+
23+
# Bullet gets older.
24+
_life += 1
25+
26+
# How many ticks do we have left?
27+
var life_left = _max_life - _life
28+
29+
# Scaling so the bullet goes from zero to full size during first appearance.
30+
var appearance_fract = min(float (_life) / float (_appearance_life), 1.0)
31+
32+
# Scale the size of the bullet so it fades towards end of life.
33+
var fract = float (life_left) / float (_max_life)
34+
35+
# Apply the appearance scaling.
36+
fract *= appearance_fract
37+
38+
# Ensure scale is never zero, just in case the engine doesn't like zero scale.
39+
fract = max(fract, 0.0001)
40+
41+
$Scaler.scale = Vector3(fract, fract, fract)
42+
43+
# If we've reached the end queue for freeing,
44+
# the engine will clear up the bullet.
45+
if _life >= _max_life:
46+
queue_free()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://dohdjr8ilotkr
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[gd_scene load_steps=12 format=3 uid="uid://2r5wc1n0ybju"]
2+
3+
[ext_resource type="Script" uid="uid://dohdjr8ilotkr" path="res://bullet.gd" id="1_v7oki"]
4+
[ext_resource type="Texture2D" uid="uid://b70s43gn8c3kx" path="res://spark_particle2.png" id="2_v8qja"]
5+
6+
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_v8qja"]
7+
bounce = 0.61
8+
9+
[sub_resource type="SphereShape3D" id="SphereShape3D_rtl8c"]
10+
radius = 0.2
11+
12+
[sub_resource type="Gradient" id="Gradient_v8qja"]
13+
14+
[sub_resource type="GradientTexture1D" id="GradientTexture1D_t4vbm"]
15+
gradient = SubResource("Gradient_v8qja")
16+
17+
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_v7oki"]
18+
direction = Vector3(0, 1, 0)
19+
initial_velocity_max = 1.0
20+
gravity = Vector3(0, 1, 0)
21+
scale_min = 0.19999999
22+
color_ramp = SubResource("GradientTexture1D_t4vbm")
23+
24+
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_t4vbm"]
25+
transparency = 1
26+
albedo_texture = ExtResource("2_v8qja")
27+
28+
[sub_resource type="QuadMesh" id="QuadMesh_rtl8c"]
29+
material = SubResource("StandardMaterial3D_t4vbm")
30+
size = Vector2(0.2, 0.2)
31+
32+
[sub_resource type="SphereMesh" id="SphereMesh_v7oki"]
33+
34+
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_v7oki"]
35+
albedo_color = Color(0.43164876, 0.5731902, 0.5013925, 1)
36+
metallic = 1.0
37+
38+
[node name="Bullet" type="RigidBody3D"]
39+
physics_material_override = SubResource("PhysicsMaterial_v8qja")
40+
script = ExtResource("1_v7oki")
41+
42+
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
43+
shape = SubResource("SphereShape3D_rtl8c")
44+
45+
[node name="GPUParticles3D" type="GPUParticles3D" parent="."]
46+
transform_align = 1
47+
process_material = SubResource("ParticleProcessMaterial_v7oki")
48+
draw_pass_1 = SubResource("QuadMesh_rtl8c")
49+
50+
[node name="Scaler" type="Node3D" parent="."]
51+
transform = Transform3D(0.001, 0, 0, 0, 0.001, 0, 0, 0, 0.001, 0, 0, 0)
52+
53+
[node name="MeshInstance3D" type="MeshInstance3D" parent="Scaler"]
54+
transform = Transform3D(0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 0, 0, 0)
55+
mesh = SubResource("SphereMesh_v7oki")
56+
skeleton = NodePath("../..")
57+
surface_material_override/0 = SubResource("StandardMaterial3D_v7oki")
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://c5avn6uhdr88"
6+
path.s3tc="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.s3tc.ctex"
7+
metadata={
8+
"imported_formats": ["s3tc_bptc"],
9+
"vram_texture": true
10+
}
11+
12+
[deps]
13+
14+
source_file="res://icon.png"
15+
dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.s3tc.ctex"]
16+
17+
[params]
18+
19+
compress/mode=2
20+
compress/high_quality=false
21+
compress/lossy_quality=0.7
22+
compress/uastc_level=0
23+
compress/rdo_quality_loss=0.0
24+
compress/hdr_compression=1
25+
compress/normal_map=0
26+
compress/channel_pack=0
27+
mipmaps/generate=true
28+
mipmaps/limit=-1
29+
roughness/mode=0
30+
roughness/src_normal=""
31+
process/channel_remap/red=0
32+
process/channel_remap/green=1
33+
process/channel_remap/blue=2
34+
process/channel_remap/alpha=3
35+
process/fix_alpha_border=true
36+
process/premult_alpha=false
37+
process/normal_map_invert_y=false
38+
process/hdr_as_srgb=false
39+
process/hdr_clamp_exposure=false
40+
process/size_limit=0
41+
detect_3d/compress_to=0
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://cb05v27t8vx5t"
6+
path.s3tc="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.s3tc.ctex"
7+
metadata={
8+
"imported_formats": ["s3tc_bptc"],
9+
"vram_texture": true
10+
}
11+
12+
[deps]
13+
14+
source_file="res://icon.svg"
15+
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.s3tc.ctex"]
16+
17+
[params]
18+
19+
compress/mode=2
20+
compress/high_quality=false
21+
compress/lossy_quality=0.7
22+
compress/uastc_level=0
23+
compress/rdo_quality_loss=0.0
24+
compress/hdr_compression=1
25+
compress/normal_map=0
26+
compress/channel_pack=0
27+
mipmaps/generate=true
28+
mipmaps/limit=-1
29+
roughness/mode=0
30+
roughness/src_normal=""
31+
process/channel_remap/red=0
32+
process/channel_remap/green=1
33+
process/channel_remap/blue=2
34+
process/channel_remap/alpha=3
35+
process/fix_alpha_border=true
36+
process/premult_alpha=false
37+
process/normal_map_invert_y=false
38+
process/hdr_as_srgb=false
39+
process/hdr_clamp_exposure=false
40+
process/size_limit=0
41+
detect_3d/compress_to=0
42+
svg/scale=1.0
43+
editor/scale_with_editor_scale=false
44+
editor/convert_colors_with_editor_theme=false

0 commit comments

Comments
 (0)