mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2025-12-31 09:49:06 +03:00
Add a 3D Rigidbody character demo (#675)
This commit is contained in:
24
3d/rigidbody_character/README.md
Normal file
24
3d/rigidbody_character/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Kinematic Character 3D
|
||||
|
||||
RigidBody character demo for 3D using a capsule for the character.
|
||||
Cubes as RigidBodies spawn in the map from above to show interaction
|
||||
with the player (jump on them, gently push them), which would be
|
||||
impossible with a KinematicBody.
|
||||
|
||||
Language: GDScript
|
||||
|
||||
Renderer: GLES 3
|
||||
|
||||
## How does it work?
|
||||
|
||||
This demo uses a [`RigidBody`](https://docs.godotengine.org/en/stable/classes/class_rigidbody.html)
|
||||
for the player, and [`StaticBody`](https://docs.godotengine.org/en/latest/classes/class_staticbody.html)
|
||||
for the level. Each has colliders, the player moves itself via
|
||||
`apply_central_impulse()` in `_physics_process()`, and collides with the level.
|
||||
|
||||
## Screenshots
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
25
3d/rigidbody_character/cube_rigidbody.tscn
Normal file
25
3d/rigidbody_character/cube_rigidbody.tscn
Normal file
@@ -0,0 +1,25 @@
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://models/white_wood.png" type="Texture" id=1]
|
||||
|
||||
[sub_resource type="BoxShape" id=1]
|
||||
extents = Vector3( 0.5, 0.5, 0.5 )
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=3]
|
||||
resource_name = "Material"
|
||||
albedo_color = Color( 0.917647, 0.384314, 0.0823529, 1 )
|
||||
albedo_texture = ExtResource( 1 )
|
||||
roughness = 0.75
|
||||
|
||||
[sub_resource type="CubeMesh" id=2]
|
||||
material = SubResource( 3 )
|
||||
size = Vector3( 1, 1, 1 )
|
||||
|
||||
[node name="cube_rigidbody" type="RigidBody"]
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="."]
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="MeshInstance" type="MeshInstance" parent="."]
|
||||
mesh = SubResource( 2 )
|
||||
material/0 = null
|
||||
27
3d/rigidbody_character/cubelib.tres
Normal file
27
3d/rigidbody_character/cubelib.tres
Normal file
File diff suppressed because one or more lines are too long
25
3d/rigidbody_character/default_env.tres
Normal file
25
3d/rigidbody_character/default_env.tres
Normal file
@@ -0,0 +1,25 @@
|
||||
[gd_resource type="Environment" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
radiance_size = 1
|
||||
sky_top_color = Color( 0.219882, 0.193725, 0.366471, 1 )
|
||||
sky_horizon_color = Color( 0.342622, 0.0655002, 0.558935, 1 )
|
||||
sky_curve = 0.0490365
|
||||
ground_bottom_color = Color( 0.0342205, 0.0333383, 0.0322154, 1 )
|
||||
ground_horizon_color = Color( 0.148289, 0.138067, 0.125119, 1 )
|
||||
ground_curve = 0.25
|
||||
sun_latitude = 55.0
|
||||
sun_longitude = -80.0
|
||||
texture_size = 0
|
||||
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
tonemap_mode = 2
|
||||
tonemap_white = 6.0
|
||||
ssao_blur = 1
|
||||
glow_levels/7 = true
|
||||
glow_strength = 0.79
|
||||
glow_bloom = 1.0
|
||||
glow_blend_mode = 0
|
||||
glow_bicubic_upscale = true
|
||||
BIN
3d/rigidbody_character/gi_probe_data.res
Normal file
BIN
3d/rigidbody_character/gi_probe_data.res
Normal file
Binary file not shown.
BIN
3d/rigidbody_character/icon.png
Normal file
BIN
3d/rigidbody_character/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
35
3d/rigidbody_character/icon.png.import
Normal file
35
3d/rigidbody_character/icon.png.import
Normal file
@@ -0,0 +1,35 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.png"
|
||||
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.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
|
||||
process/normal_map_invert_y=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
9
3d/rigidbody_character/level.gd
Normal file
9
3d/rigidbody_character/level.gd
Normal file
@@ -0,0 +1,9 @@
|
||||
extends Spatial
|
||||
|
||||
# Random spawn of Rigidbody cubes.
|
||||
func _on_SpawnTimer_timeout():
|
||||
var new_rb = preload("res://cube_rigidbody.tscn").instance()
|
||||
new_rb.translation.y = 15
|
||||
new_rb.translation.x = rand_range(-5, 5)
|
||||
new_rb.translation.z = rand_range(-5, 5)
|
||||
add_child(new_rb)
|
||||
128
3d/rigidbody_character/level.tscn
Normal file
128
3d/rigidbody_character/level.tscn
Normal file
@@ -0,0 +1,128 @@
|
||||
[gd_scene load_steps=11 format=2]
|
||||
|
||||
[ext_resource path="res://cubelib.tres" type="MeshLibrary" id=1]
|
||||
[ext_resource path="res://player/cubio.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://models/cube.mesh" type="ArrayMesh" id=3]
|
||||
[ext_resource path="res://models/mushroom.glb" type="PackedScene" id=5]
|
||||
[ext_resource path="res://level.gd" type="Script" id=6]
|
||||
[ext_resource path="res://cube_rigidbody.tscn" type="PackedScene" id=7]
|
||||
|
||||
[sub_resource type="BoxShape" id=1]
|
||||
margin = 0.001
|
||||
extents = Vector3( 0.5, 0.5, 0.5 )
|
||||
|
||||
[sub_resource type="Animation" id=2]
|
||||
length = 10.0
|
||||
loop = true
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath(".:translation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0, 1, 4, 6, 9, 10 ),
|
||||
"transitions": PoolRealArray( 1, -2, 1, -2, 1, 1 ),
|
||||
"update": 0,
|
||||
"values": [ Vector3( 0.5, 4.5, -2.5 ), Vector3( 0.5, 4.5, -2.5 ), Vector3( 0.5, 8.5, -2.5 ), Vector3( 0.5, 8.5, -2.5 ), Vector3( 0.5, 4.5, -2.5 ), Vector3( 0.5, 4.5, -2.5 ) ]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=3]
|
||||
length = 10.0
|
||||
loop = true
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath(".:translation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0, 2, 4.5, 6, 9 ),
|
||||
"transitions": PoolRealArray( 1, -2, 1, -2, 1 ),
|
||||
"update": 0,
|
||||
"values": [ Vector3( -3.5, 8.5, 4.5 ), Vector3( -3.5, 8.5, 4.5 ), Vector3( 3.5, 8.5, 4.5 ), Vector3( 3.5, 8.5, 4.5 ), Vector3( -3.5, 8.5, 4.5 ) ]
|
||||
}
|
||||
|
||||
[sub_resource type="BoxShape" id=4]
|
||||
|
||||
[node name="World" type="Spatial"]
|
||||
script = ExtResource( 6 )
|
||||
__meta__ = {
|
||||
"__editor_plugin_screen__": "3D"
|
||||
}
|
||||
|
||||
[node name="GridMap" type="GridMap" parent="."]
|
||||
mesh_library = ExtResource( 1 )
|
||||
cell_size = Vector3( 1, 1, 1 )
|
||||
data = {
|
||||
"cells": PoolIntArray( 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 65530, 0, 0, 65531, 0, 0, 65532, 0, 0, 65533, 0, 0, 65534, 0, 0, 65535, 0, 0, 196603, 0, 0, 196604, 0, 0, 524292, 0, 0, 589820, 0, 0, 786432, 0, 0, 851967, 0, 0, 0, 1, 0, 1, 1, 0, 2, 1, 0, 3, 1, 0, 4, 1, 0, 65530, 1, 0, 65531, 1, 0, 65532, 1, 0, 65533, 1, 0, 65534, 1, 0, 65535, 1, 0, 131075, 1, 0, 196603, 1, 0, 196604, 1, 0, 524292, 1, 0, 589820, 1, 0, 786432, 1, 0, 851967, 1, 0, 0, 2, 0, 1, 2, 0, 2, 2, 0, 3, 2, 0, 4, 2, 0, 65530, 2, 0, 65531, 2, 0, 65532, 2, 0, 65533, 2, 0, 65534, 2, 0, 65535, 2, 0, 131075, 2, 0, 196603, 2, 0, 196604, 2, 0, 524292, 2, 0, 589820, 2, 0, 786432, 2, 0, 786433, 2, 0, 851966, 2, 0, 851967, 2, 0, 0, 3, 0, 1, 3, 0, 2, 3, 0, 3, 3, 0, 4, 3, 0, 65530, 3, 0, 65531, 3, 0, 65532, 3, 0, 65533, 3, 0, 65534, 3, 0, 65535, 3, 0, 196603, 3, 0, 524291, 3, 0, 524292, 3, 0, 589820, 3, 0, 786432, 3, 0, 786433, 3, 0, 851966, 3, 0, 851967, 3, 0, 0, 4, 0, 1, 4, 0, 2, 4, 0, 3, 4, 0, 4, 4, 0, 65530, 4, 0, 65531, 4, 0, 65532, 4, 0, 65533, 4, 0, 65534, 4, 0, 65535, 4, 0, 196603, 4, 0, 0, 5, 0, 1, 5, 0, 2, 5, 0, 3, 5, 0, 4, 5, 0, 65530, 5, 0, 65531, 5, 0, 65532, 5, 0, 65533, 5, 0, 65534, 5, 0, 65535, 5, 0, 131075, 5, 0, 0, 6, 0, 1, 6, 0, 2, 6, 0, 3, 6, 0, 4, 6, 0, 65530, 6, 0, 65531, 6, 0, 65532, 6, 0, 65533, 6, 0, 65534, 6, 0, 65535, 6, 0, 131075, 6, 0, 196603, 6, 0, 0, 7, 0, 1, 7, 0, 2, 7, 0, 3, 7, 0, 4, 7, 0, 65530, 7, 0, 65531, 7, 0, 65532, 7, 0, 65533, 7, 0, 65534, 7, 0, 65535, 7, 0, 131075, 7, 0, 196603, 7, 0, 0, 8, 0, 1, 8, 0, 2, 8, 0, 3, 8, 0, 4, 8, 0, 65530, 8, 0, 65531, 8, 0, 65532, 8, 0, 65533, 8, 0, 65534, 8, 0, 65535, 8, 0, 131075, 8, 0, 196603, 8, 0, 196604, 8, 0, 0, 9, 0, 1, 9, 0, 2, 9, 0, 3, 9, 0, 4, 9, 0, 65530, 9, 0, 65531, 9, 0, 65532, 9, 0, 65533, 9, 0, 65534, 9, 0, 65535, 9, 0, 131073, 9, 0, 131074, 9, 0, 131075, 9, 0, 196603, 9, 0, 196604, 9, 0, 196605, 9, 0, 196608, 9, 0, 262142, 9, 0, 0, 10, 0, 1, 10, 0, 2, 10, 0, 3, 10, 0, 4, 10, 0, 65530, 10, 0, 65531, 10, 0, 65532, 10, 0, 65533, 10, 0, 65534, 10, 0, 65535, 10, 0, 0, 11, 0, 1, 11, 0, 2, 11, 0, 3, 11, 0, 4, 11, 0, 65530, 11, 0, 65531, 11, 0, 65532, 11, 0, 65533, 11, 0, 65534, 11, 0, 65535, 11, 0, 0, 65532, 0, 1, 65532, 0, 2, 65532, 0, 3, 65532, 0, 4, 65532, 0, 65530, 65532, 0, 65531, 65532, 0, 65532, 65532, 0, 65533, 65532, 0, 65534, 65532, 0, 65535, 65532, 0, 0, 65533, 0, 1, 65533, 0, 2, 65533, 0, 3, 65533, 0, 4, 65533, 0, 65530, 65533, 0, 65531, 65533, 0, 65532, 65533, 0, 65533, 65533, 0, 65534, 65533, 0, 65535, 65533, 0, 262145, 65533, 0, 262146, 65533, 0, 262147, 65533, 0, 589822, 65533, 0, 589823, 65533, 0, 655363, 65533, 0, 655364, 65533, 0, 720897, 65533, 0, 720898, 65533, 0, 786432, 65533, 0, 851967, 65533, 0, 0, 65534, 0, 1, 65534, 0, 2, 65534, 0, 3, 65534, 0, 4, 65534, 0, 65530, 65534, 0, 65531, 65534, 0, 65532, 65534, 0, 65533, 65534, 0, 65534, 65534, 0, 65535, 65534, 0, 65536, 65534, 0, 131071, 65534, 0, 196603, 65534, 0, 196604, 65534, 0, 196605, 65534, 0, 196606, 65534, 0, 196607, 65534, 0, 589822, 65534, 0, 589828, 65534, 0, 786432, 65534, 0, 851967, 65534, 0, 0, 65535, 0, 1, 65535, 0, 2, 65535, 0, 3, 65535, 0, 4, 65535, 0, 65530, 65535, 0, 65531, 65535, 0, 65532, 65535, 0, 65533, 65535, 0, 65534, 65535, 0, 65535, 65535, 0, 196603, 65535, 0, 196604, 65535, 0, 196611, 65535, 0, 589820, 65535, 0, 589821, 65535, 0, 589822, 65535, 0, 589828, 65535, 0, 786432, 65535, 0, 851967, 65535, 0 )
|
||||
}
|
||||
__meta__ = {
|
||||
"_editor_clip_": 0,
|
||||
"_editor_floor_": Vector3( 0, 12, 0 )
|
||||
}
|
||||
|
||||
[node name="DirectionalLight" type="DirectionalLight" parent="."]
|
||||
transform = Transform( -0.173649, 0.806707, -0.564863, 0, 0.573576, 0.819152, 0.984808, 0.142244, -0.0996007, 0, 0, 0 )
|
||||
light_energy = 1.3
|
||||
shadow_enabled = true
|
||||
shadow_bias = -0.02
|
||||
shadow_reverse_cull_face = true
|
||||
directional_shadow_mode = 0
|
||||
directional_shadow_normal_bias = 0.0
|
||||
directional_shadow_bias_split_scale = 0.0
|
||||
directional_shadow_max_distance = 20.0
|
||||
|
||||
[node name="Cubio" parent="." instance=ExtResource( 2 )]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1.5, 2, 4 )
|
||||
|
||||
[node name="Elevator1" type="KinematicBody" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 4.5, -2.5 )
|
||||
input_capture_on_drag = true
|
||||
|
||||
[node name="Mesh" type="MeshInstance" parent="Elevator1"]
|
||||
mesh = ExtResource( 3 )
|
||||
material/0 = null
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="Elevator1"]
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="Elevator1"]
|
||||
autoplay = "updown1"
|
||||
playback_process_mode = 0
|
||||
anims/updown1 = SubResource( 2 )
|
||||
|
||||
[node name="Elevator2" type="KinematicBody" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -3.5, 8.5, 4.5 )
|
||||
|
||||
[node name="Mesh" type="MeshInstance" parent="Elevator2"]
|
||||
mesh = ExtResource( 3 )
|
||||
material/0 = null
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="Elevator2"]
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="Elevator2"]
|
||||
autoplay = "side"
|
||||
playback_process_mode = 0
|
||||
anims/side = SubResource( 3 )
|
||||
anims/updown1 = SubResource( 2 )
|
||||
|
||||
[node name="Princess" type="Area" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 13.25, 3 )
|
||||
|
||||
[node name="Mushroom" parent="Princess" instance=ExtResource( 5 )]
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="Princess"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
|
||||
shape = SubResource( 4 )
|
||||
|
||||
[node name="SpawnTimer" type="Timer" parent="."]
|
||||
wait_time = 2.0
|
||||
autostart = true
|
||||
|
||||
[node name="cube_rigidbody" parent="." instance=ExtResource( 7 )]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.416964, 3.3565, 2.6332 )
|
||||
|
||||
[connection signal="body_entered" from="Princess" to="Cubio" method="_on_tcube_body_entered"]
|
||||
[connection signal="timeout" from="SpawnTimer" to="." method="_on_SpawnTimer_timeout"]
|
||||
BIN
3d/rigidbody_character/models/cube.glb
Normal file
BIN
3d/rigidbody_character/models/cube.glb
Normal file
Binary file not shown.
1065
3d/rigidbody_character/models/cube.glb.import
Normal file
1065
3d/rigidbody_character/models/cube.glb.import
Normal file
File diff suppressed because it is too large
Load Diff
BIN
3d/rigidbody_character/models/cube.mesh
Normal file
BIN
3d/rigidbody_character/models/cube.mesh
Normal file
Binary file not shown.
9
3d/rigidbody_character/models/cube_material.tres
Normal file
9
3d/rigidbody_character/models/cube_material.tres
Normal file
@@ -0,0 +1,9 @@
|
||||
[gd_resource type="SpatialMaterial" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://models/white_wood.png" type="Texture" id=1]
|
||||
|
||||
[resource]
|
||||
resource_name = "Material"
|
||||
albedo_color = Color( 0.5, 0.25, 1, 1 )
|
||||
albedo_texture = ExtResource( 1 )
|
||||
roughness = 0.75
|
||||
BIN
3d/rigidbody_character/models/mushroom.glb
Normal file
BIN
3d/rigidbody_character/models/mushroom.glb
Normal file
Binary file not shown.
1065
3d/rigidbody_character/models/mushroom.glb.import
Normal file
1065
3d/rigidbody_character/models/mushroom.glb.import
Normal file
File diff suppressed because it is too large
Load Diff
8
3d/rigidbody_character/models/white_cube_material.tres
Normal file
8
3d/rigidbody_character/models/white_cube_material.tres
Normal file
@@ -0,0 +1,8 @@
|
||||
[gd_resource type="SpatialMaterial" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://models/white_wood.png" type="Texture" id=1]
|
||||
|
||||
[resource]
|
||||
resource_name = "Material"
|
||||
albedo_texture = ExtResource( 1 )
|
||||
roughness = 0.75
|
||||
BIN
3d/rigidbody_character/models/white_wood.png
Normal file
BIN
3d/rigidbody_character/models/white_wood.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 168 KiB |
38
3d/rigidbody_character/models/white_wood.png.import
Normal file
38
3d/rigidbody_character/models/white_wood.png.import
Normal file
@@ -0,0 +1,38 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path.s3tc="res://.import/white_wood.png-821b7bf9b3881778c9bff1c965d8a87c.s3tc.stex"
|
||||
path.etc2="res://.import/white_wood.png-821b7bf9b3881778c9bff1c965d8a87c.etc2.stex"
|
||||
path.etc="res://.import/white_wood.png-821b7bf9b3881778c9bff1c965d8a87c.etc.stex"
|
||||
metadata={
|
||||
"imported_formats": [ "s3tc", "etc2", "etc" ],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://models/white_wood.png"
|
||||
dest_files=[ "res://.import/white_wood.png-821b7bf9b3881778c9bff1c965d8a87c.s3tc.stex", "res://.import/white_wood.png-821b7bf9b3881778c9bff1c965d8a87c.etc2.stex", "res://.import/white_wood.png-821b7bf9b3881778c9bff1c965d8a87c.etc.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=2
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=true
|
||||
flags/filter=true
|
||||
flags/mipmaps=true
|
||||
flags/anisotropic=true
|
||||
flags/srgb=1
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
process/normal_map_invert_y=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=false
|
||||
svg/scale=1.0
|
||||
39
3d/rigidbody_character/player/cubio.gd
Normal file
39
3d/rigidbody_character/player/cubio.gd
Normal file
@@ -0,0 +1,39 @@
|
||||
extends RigidBody
|
||||
|
||||
onready var raycast = $RayCast
|
||||
onready var camera = $Target/Camera
|
||||
onready var start_position = translation
|
||||
|
||||
func _physics_process(_delta):
|
||||
if Input.is_action_just_pressed("exit"):
|
||||
get_tree().quit()
|
||||
if Input.is_action_just_pressed("reset_position"):
|
||||
translation = start_position
|
||||
return
|
||||
|
||||
var dir = Vector3()
|
||||
dir.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
|
||||
dir.z = Input.get_action_strength("move_back") - Input.get_action_strength("move_forward")
|
||||
|
||||
# Get the camera's transform basis, but remove the X rotation such
|
||||
# that the Y axis is up and Z is horizontal.
|
||||
var cam_basis = camera.global_transform.basis
|
||||
var basis = cam_basis.rotated(cam_basis.x, -cam_basis.get_euler().x)
|
||||
dir = basis.xform(dir)
|
||||
|
||||
apply_central_impulse(dir.normalized() / 10)
|
||||
|
||||
# Jumping code.
|
||||
if on_ground() and Input.is_action_pressed("jump"):
|
||||
apply_central_impulse(Vector3.UP)
|
||||
|
||||
|
||||
# Test if there is a body below the player.
|
||||
func on_ground():
|
||||
if raycast.is_colliding():
|
||||
return true
|
||||
|
||||
|
||||
func _on_tcube_body_entered(body):
|
||||
if body == self:
|
||||
get_node("WinText").show()
|
||||
64
3d/rigidbody_character/player/cubio.tscn
Normal file
64
3d/rigidbody_character/player/cubio.tscn
Normal file
@@ -0,0 +1,64 @@
|
||||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://player/cubio.gd" type="Script" id=1]
|
||||
[ext_resource path="res://player/follow_camera.gd" type="Script" id=3]
|
||||
[ext_resource path="res://models/white_cube_material.tres" type="Material" id=4]
|
||||
|
||||
[sub_resource type="CapsuleMesh" id=6]
|
||||
radius = 0.5
|
||||
mid_height = 0.7
|
||||
|
||||
[sub_resource type="CapsuleShape" id=5]
|
||||
radius = 0.5
|
||||
height = 0.7
|
||||
|
||||
[node name="RigidBody" type="RigidBody"]
|
||||
can_sleep = false
|
||||
axis_lock_angular_x = true
|
||||
axis_lock_angular_y = true
|
||||
axis_lock_angular_z = true
|
||||
linear_damp = 0.5
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="CubeMesh" type="MeshInstance" parent="."]
|
||||
_import_path = NodePath("cube-col")
|
||||
transform = Transform( 0.9, 0, 0, 0, -3.93403e-08, -0.9, 0, 0.9, -3.93403e-08, 0, 0, 0 )
|
||||
mesh = SubResource( 6 )
|
||||
skeleton = NodePath("")
|
||||
material/0 = ExtResource( 4 )
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 )
|
||||
shape = SubResource( 5 )
|
||||
|
||||
[node name="Target" type="Spatial" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8, 0 )
|
||||
|
||||
[node name="Camera" type="Camera" parent="Target"]
|
||||
transform = Transform( 0.34202, -0.321394, 0.883022, 0, 0.939693, 0.34202, -0.939693, -0.116978, 0.321394, 2, 0.5, 0.913381 )
|
||||
fov = 74.0
|
||||
near = 0.1
|
||||
far = 50.0
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="WinText" type="CenterContainer" parent="."]
|
||||
visible = false
|
||||
anchor_right = 1.0
|
||||
margin_bottom = 100.0
|
||||
|
||||
[node name="Holder" type="Control" parent="WinText"]
|
||||
margin_left = 512.0
|
||||
margin_top = 50.0
|
||||
margin_right = 512.0
|
||||
margin_bottom = 50.0
|
||||
|
||||
[node name="TextLabel" type="Label" parent="WinText/Holder"]
|
||||
margin_left = -354.0
|
||||
margin_bottom = 14.0
|
||||
rect_scale = Vector2( 2, 2 )
|
||||
text = "Thank You, Cubio! But the Princess is in Another Demo!"
|
||||
align = 1
|
||||
valign = 1
|
||||
|
||||
[node name="RayCast" type="RayCast" parent="."]
|
||||
enabled = true
|
||||
41
3d/rigidbody_character/player/follow_camera.gd
Normal file
41
3d/rigidbody_character/player/follow_camera.gd
Normal file
@@ -0,0 +1,41 @@
|
||||
extends Camera
|
||||
|
||||
var collision_exception = []
|
||||
export var min_distance = 0.5
|
||||
export var max_distance = 3.0
|
||||
export var angle_v_adjust = 0.0
|
||||
var max_height = 2.0
|
||||
var min_height = 0
|
||||
onready var target_node: Spatial = get_parent()
|
||||
|
||||
|
||||
func _ready():
|
||||
collision_exception.append(target_node.get_parent().get_rid())
|
||||
# Detaches the camera transform from the parent spatial node
|
||||
set_as_toplevel(true)
|
||||
|
||||
|
||||
func _physics_process(_delta):
|
||||
var target_pos: Vector3 = target_node.global_transform.origin
|
||||
var camera_pos: Vector3 = global_transform.origin
|
||||
|
||||
var delta_pos: Vector3 = camera_pos - target_pos
|
||||
|
||||
# Regular delta follow
|
||||
|
||||
# Check ranges
|
||||
if delta_pos.length() < min_distance:
|
||||
delta_pos = delta_pos.normalized() * min_distance
|
||||
elif delta_pos.length() > max_distance:
|
||||
delta_pos = delta_pos.normalized() * max_distance
|
||||
|
||||
# Check upper and lower height
|
||||
delta_pos.y = clamp(delta_pos.y, min_height, max_height)
|
||||
camera_pos = target_pos + delta_pos
|
||||
|
||||
look_at_from_position(camera_pos, target_pos, Vector3.UP)
|
||||
|
||||
# Turn a little up or down
|
||||
var t = transform
|
||||
t.basis = Basis(t.basis[0], deg2rad(angle_v_adjust)) * t.basis
|
||||
transform = t
|
||||
93
3d/rigidbody_character/project.godot
Normal file
93
3d/rigidbody_character/project.godot
Normal file
@@ -0,0 +1,93 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=4
|
||||
|
||||
[application]
|
||||
|
||||
config/name="RigidBody Character 3D"
|
||||
config/description="Rigidbody character demo for 3D using a capsule for the character.
|
||||
"
|
||||
run/main_scene="res://level.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[gdnative]
|
||||
|
||||
singletons=[ ]
|
||||
|
||||
[input]
|
||||
|
||||
jump={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_back={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
move_forward={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
move_left={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
move_right={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
reset_position={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":82,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":2,"pressure":0.0,"pressed":false,"script":null)
|
||||
]
|
||||
}
|
||||
exit={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[physics]
|
||||
|
||||
common/physics_fps=120
|
||||
|
||||
[rasterizer]
|
||||
|
||||
shadow_filter=3
|
||||
|
||||
[rendering]
|
||||
|
||||
quality/driver/fallback_to_gles2=true
|
||||
vram_compression/import_etc=true
|
||||
quality/shadows/filter_mode=2
|
||||
quality/filters/anisotropic_filter_level=16
|
||||
quality/filters/msaa=2
|
||||
environment/default_environment="res://default_env.tres"
|
||||
quality/filters/msaa.mobile=0
|
||||
quality/filters/anisotropic_filter_level.mobile=4
|
||||
0
3d/rigidbody_character/screenshots/.gdignore
Normal file
0
3d/rigidbody_character/screenshots/.gdignore
Normal file
BIN
3d/rigidbody_character/screenshots/editor.png
Normal file
BIN
3d/rigidbody_character/screenshots/editor.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 MiB |
BIN
3d/rigidbody_character/screenshots/ingame.png
Normal file
BIN
3d/rigidbody_character/screenshots/ingame.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 843 KiB |
Reference in New Issue
Block a user