Skip to content

Commit 1a2cb75

Browse files
committed
3D Physics and Other Stuff
-=-=-=-=-=-=-=-=-=-=-=-=-= -New Vehicle (Based on Bullet's RaycastVehicle) - Vehiclebody/VehicleWheel. Demo will come soon, old vehicle (CarBody) will go away soon too. -A lot of fixes to the 3D physics engine -Added KinematicBody with demo -Fixed the space query API for 2D (demo will come soon). 3D is WIP. -Fixed long-standing bug with body_enter/body_exit for Area and Area2D -Performance variables now includes physics (active bodies, collision pairs and islands) -Ability to see what's inside of instanced scenes! -Fixed Blend Shapes (no bs+skeleton yet) -Added an Android JavaClassWrapper singleton for using Android native classes directly from GDScript. This is very Alpha!
1 parent 89fa707 commit 1a2cb75

File tree

82 files changed

+5153
-848
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+5153
-848
lines changed

SConstruct

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ for p in platform_list:
205205

206206
flag_list = platform_flags[p]
207207
for f in flag_list:
208-
env[f[0]] = f[1]
209-
print(f[0]+":"+f[1])
208+
if not (f[0] in ARGUMENTS): # allow command line to override platform flags
209+
env[f[0]] = f[1]
210+
print(f[0]+":"+f[1])
210211

211212
env.module_list=[]
212213

core/global_constants.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,26 @@ static _GlobalConstant _global_constants[]={
445445
BIND_GLOBAL_CONSTANT( ERR_BUG ), ///< a bug in the software certainly happened ), due to a double check failing or unexpected behavior.
446446
BIND_GLOBAL_CONSTANT( ERR_WTF ),
447447

448-
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_NONE ),
449-
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_RANGE ),
450-
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_EXP_RANGE ),
451-
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_ENUM ),
452-
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_LENGTH ),
453-
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_FLAGS ),
454-
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_FILE ),
455-
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_DIR ),
456-
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_RESOURCE_TYPE ),
448+
449+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_NONE ),
450+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_RANGE ),
451+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_EXP_RANGE ),
452+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_ENUM ),
453+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_EXP_EASING ),
454+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_LENGTH ),
455+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_KEY_ACCEL ),
456+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_FLAGS ),
457+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_ALL_FLAGS ),
458+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_FILE ),
459+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_DIR ),
460+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_GLOBAL_FILE ),
461+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_GLOBAL_DIR ),
462+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_RESOURCE_TYPE ),
463+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_MULTILINE_TEXT ),
464+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_COLOR_NO_ALPHA ),
465+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_IMAGE_COMPRESS_LOSSY ),
466+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS ),
467+
457468

458469
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_STORAGE ),
459470
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_STORAGE ),

core/math/vector3.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ struct Vector3 {
111111
_FORCE_INLINE_ real_t distance_to(const Vector3& p_b) const;
112112
_FORCE_INLINE_ real_t distance_squared_to(const Vector3& p_b) const;
113113

114+
115+
116+
_FORCE_INLINE_ Vector3 slide(const Vector3& p_vec) const;
117+
_FORCE_INLINE_ Vector3 reflect(const Vector3& p_vec) const;
118+
119+
114120
/* Operators */
115121

116122
_FORCE_INLINE_ Vector3& operator+=(const Vector3& p_v);
@@ -368,6 +374,16 @@ void Vector3::zero() {
368374
x=y=z=0;
369375
}
370376

377+
Vector3 Vector3::slide(const Vector3& p_vec) const {
378+
379+
return p_vec - *this * this->dot(p_vec);
380+
}
381+
Vector3 Vector3::reflect(const Vector3& p_vec) const {
382+
383+
return p_vec - *this * this->dot(p_vec) * 2.0;
384+
385+
}
386+
371387
#endif
372388

373389
#endif // VECTOR3_H

core/variant_call.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
331331
VCALL_LOCALMEM0R(Vector3, abs);
332332
VCALL_LOCALMEM1R(Vector3, distance_to);
333333
VCALL_LOCALMEM1R(Vector3, distance_squared_to);
334+
VCALL_LOCALMEM1R(Vector3, slide);
335+
VCALL_LOCALMEM1R(Vector3, reflect);
336+
334337

335338
VCALL_LOCALMEM0R(Plane,normalized);
336339
VCALL_LOCALMEM0R(Plane,center);
@@ -1236,6 +1239,8 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
12361239
ADDFUNC0(VECTOR3,VECTOR3,Vector3,abs,varray());
12371240
ADDFUNC1(VECTOR3,REAL,Vector3,distance_to,VECTOR3,"b",varray());
12381241
ADDFUNC1(VECTOR3,REAL,Vector3,distance_squared_to,VECTOR3,"b",varray());
1242+
ADDFUNC1(VECTOR3,VECTOR3,Vector3,slide,VECTOR3,"by",varray());
1243+
ADDFUNC1(VECTOR3,VECTOR3,Vector3,reflect,VECTOR3,"by",varray());
12391244

12401245
ADDFUNC0(PLANE,PLANE,Plane,normalized,varray());
12411246
ADDFUNC0(PLANE,VECTOR3,Plane,center,varray());

core/variant_op.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
11451145
if (p_value.type!=Variant::VECTOR3)
11461146
return;
11471147

1148+
11481149
if (p_index.get_type()==Variant::STRING) {
11491150
//scalar name
11501151

@@ -1181,6 +1182,24 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
11811182
v->set_axis(index,p_value);
11821183
return;
11831184
}
1185+
} else if (p_index.get_type()==Variant::STRING) {
1186+
1187+
const String *str=reinterpret_cast<const String*>(p_index._data._mem);
1188+
Matrix3 *v=_data._matrix3;
1189+
1190+
if (*str=="x") {
1191+
valid=true;
1192+
v->set_axis(0,p_value);
1193+
return;
1194+
} else if (*str=="y" ) {
1195+
valid=true;
1196+
v->set_axis(1,p_value);
1197+
return;
1198+
} else if (*str=="z" ) {
1199+
valid=true;
1200+
v->set_axis(2,p_value);
1201+
return;
1202+
}
11841203
}
11851204

11861205
} break;
@@ -2021,6 +2040,21 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
20212040
valid=true;
20222041
return v->get_axis(index);
20232042
}
2043+
} else if (p_index.get_type()==Variant::STRING) {
2044+
2045+
const String *str=reinterpret_cast<const String*>(p_index._data._mem);
2046+
const Matrix3 *v=_data._matrix3;
2047+
2048+
if (*str=="x") {
2049+
valid=true;
2050+
return v->get_axis(0);
2051+
} else if (*str=="y" ) {
2052+
valid=true;
2053+
return v->get_axis(1);
2054+
} else if (*str=="z" ) {
2055+
valid=true;
2056+
return v->get_axis(2);
2057+
}
20242058
}
20252059

20262060
} break;

demos/2d/platformer/stage.xml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<resource_file type="PackedScene" subresource_count="9" version="1.0" version_name="Godot Engine v1.0.3917-beta1">
3-
<ext_resource path="res://music.ogg" type="AudioStream"></ext_resource>
43
<ext_resource path="res://tileset.xml" type="TileSet"></ext_resource>
4+
<ext_resource path="res://music.ogg" type="AudioStream"></ext_resource>
55
<ext_resource path="res://coin.xml" type="PackedScene"></ext_resource>
66
<ext_resource path="res://player.xml" type="PackedScene"></ext_resource>
7-
<ext_resource path="res://moving_platform.xml" type="PackedScene"></ext_resource>
87
<ext_resource path="res://seesaw.xml" type="PackedScene"></ext_resource>
8+
<ext_resource path="res://moving_platform.xml" type="PackedScene"></ext_resource>
99
<ext_resource path="res://enemy.xml" type="PackedScene"></ext_resource>
1010
<ext_resource path="res://parallax_bg.xml" type="PackedScene"></ext_resource>
1111
<main_resource>
1212
<dictionary name="_bundled" shared="false">
1313
<string> "names" </string>
14-
<string_array len="119">
14+
<string_array len="122">
1515
<string> "stage" </string>
1616
<string> "Node" </string>
17+
<string> "_import_path" </string>
1718
<string> "__meta__" </string>
1819
<string> "tile_map" </string>
1920
<string> "TileMap" </string>
@@ -28,7 +29,9 @@
2829
<string> "quadrant_size" </string>
2930
<string> "tile_set" </string>
3031
<string> "tile_data" </string>
31-
<string> "collision_layers" </string>
32+
<string> "collision/friction" </string>
33+
<string> "collision/bounce" </string>
34+
<string> "collision/layers" </string>
3235
<string> "coins" </string>
3336
<string> "coin" </string>
3437
<string> "Area2D" </string>
@@ -140,6 +143,7 @@
140143
<int> 66 </int>
141144
<string> "variants" </string>
142145
<array len="96" shared="false">
146+
<node_path> "" </node_path>
143147
<dictionary shared="false">
144148
<string> "__editor_plugin_states__" </string>
145149
<dictionary shared="false">
@@ -164,7 +168,7 @@
164168
<string> "use_snap" </string>
165169
<bool> False </bool>
166170
<string> "ofs" </string>
167-
<vector2> 418.81, 615.088 </vector2>
171+
<vector2> -177.089, 415.221 </vector2>
168172
<string> "snap" </string>
169173
<int> 10 </int>
170174
</dictionary>
@@ -318,7 +322,7 @@
318322
<vector2> 4236.75, 541.058 </vector2>
319323
<vector2> 4172.75, 541.058 </vector2>
320324
<resource resource_type="PackedScene" path="res://player.xml"> </resource>
321-
<vector2> 236.879, 1051.15 </vector2>
325+
<vector2> 251.684, 1045.6 </vector2>
322326
<resource resource_type="PackedScene" path="res://moving_platform.xml"> </resource>
323327
<vector2> 1451.86, 742.969 </vector2>
324328
<vector2> 0, 140 </vector2>
@@ -349,16 +353,15 @@
349353
<real> -202 </real>
350354
<real> 358 </real>
351355
<real> -10 </real>
352-
<node_path> "" </node_path>
353356
<int> 2 </int>
354-
<real> 14 </real>
357+
<real> 7 </real>
355358
<real> 14.769231 </real>
356-
<string> "This is a simple demo on how to make a platformer game with Godot.&#10;This version uses physics and the 2D physics engine for motion and collision.&#10;&#10;The demo also shows the benefits of using the scene system, where coins,&#10;enemies and the player are edited separatedly and instanced in the stage.&#10;&#10;To edit the base tiles for the tileset, open the tileset_edit.xml file and follow &#10;instructions.&#10;" </string>
359+
<string> "This is a simple demo on how to make a platformer game with Godot.&#22;This version uses physics and the 2D physics engine for motion and collision.&#22;&#22;The demo also shows the benefits of using the scene system, where coins,&#22;enemies and the player are edited separatedly and instanced in the stage.&#22;&#22;To edit the base tiles for the tileset, open the tileset_edit.xml file and follow &#22;instructions.&#22;" </string>
357360
<int> 0 </int>
358361
<real> -1 </real>
359362
</array>
360363
<string> "nodes" </string>
361-
<int_array len="690"> -1, -1, 1, 0, -1, 1, 2, 0, 0, 0, 0, 4, 3, -1, 13, 5, 1, 6, 2, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12, 7, 13, 8, 14, 9, 15, 10, 16, 11, 2, 12, 0, 0, 0, 1, 17, -1, 1, 2, 13, 0, 2, 0, 19, 18, 14, 1, 9, 15, 0, 2, 0, 19, 20, 14, 1, 9, 16, 0, 2, 0, 19, 21, 14, 1, 9, 17, 0, 2, 0, 19, 22, 14, 1, 9, 18, 0, 2, 0, 19, 23, 14, 1, 9, 19, 0, 2, 0, 19, 24, 14, 1, 9, 20, 0, 2, 0, 19, 25, 14, 1, 9, 21, 0, 2, 0, 19, 26, 14, 1, 9, 22, 0, 2, 0, 19, 27, 14, 1, 9, 23, 0, 2, 0, 19, 28, 14, 1, 9, 24, 0, 2, 0, 19, 29, 14, 1, 9, 25, 0, 2, 0, 19, 30, 14, 1, 9, 26, 0, 2, 0, 19, 31, 14, 1, 9, 27, 0, 2, 0, 19, 32, 14, 1, 9, 28, 0, 2, 0, 19, 33, 14, 1, 9, 29, 0, 2, 0, 19, 34, 14, 1, 9, 30, 0, 2, 0, 19, 35, 14, 1, 9, 31, 0, 2, 0, 19, 36, 14, 1, 9, 32, 0, 2, 0, 19, 37, 14, 1, 9, 33, 0, 2, 0, 19, 38, 14, 1, 9, 34, 0, 2, 0, 19, 39, 14, 1, 9, 35, 0, 2, 0, 19, 40, 14, 1, 9, 36, 0, 2, 0, 19, 41, 14, 1, 9, 37, 0, 2, 0, 19, 42, 14, 1, 9, 38, 0, 2, 0, 19, 43, 14, 1, 9, 39, 0, 2, 0, 19, 44, 14, 1, 9, 40, 0, 2, 0, 19, 45, 14, 1, 9, 41, 0, 2, 0, 19, 46, 14, 1, 9, 42, 0, 2, 0, 19, 47, 14, 1, 9, 43, 0, 2, 0, 19, 48, 14, 1, 9, 44, 0, 2, 0, 19, 49, 14, 1, 9, 45, 0, 2, 0, 19, 50, 14, 1, 9, 46, 0, 2, 0, 19, 51, 14, 1, 9, 47, 0, 2, 0, 19, 52, 14, 1, 9, 48, 0, 2, 0, 19, 53, 14, 1, 9, 49, 0, 2, 0, 19, 54, 14, 1, 9, 50, 0, 2, 0, 19, 55, 14, 1, 9, 51, 0, 2, 0, 19, 56, 14, 1, 9, 52, 0, 2, 0, 19, 57, 14, 1, 9, 53, 0, 2, 0, 19, 58, 14, 1, 9, 54, 0, 2, 0, 19, 59, 14, 1, 9, 55, 0, 2, 0, 19, 60, 14, 1, 9, 56, 0, 0, 0, 62, 61, 57, 1, 9, 58, 0, 0, 0, 1, 63, -1, 0, 0, 46, 0, 65, 64, 59, 3, 9, 60, 66, 61, 67, 62, 0, 46, 0, 65, 68, 59, 3, 9, 63, 66, 64, 67, 65, 0, 46, 0, 65, 69, 59, 3, 9, 66, 66, 67, 67, 65, 0, 46, 0, 65, 70, 68, 1, 9, 69, 0, 0, 0, 72, 71, -1, 6, 73, 70, 74, 3, 75, 1, 76, 71, 77, 1, 78, 3, 0, 0, 0, 1, 79, -1, 0, 0, 52, 0, 62, 80, 72, 1, 9, 73, 0, 52, 0, 62, 81, 72, 1, 9, 74, 0, 52, 0, 62, 82, 72, 1, 9, 75, 0, 52, 0, 62, 83, 72, 1, 9, 76, 0, 52, 0, 62, 84, 72, 1, 9, 77, 0, 52, 0, 62, 85, 72, 1, 9, 78, 0, 52, 0, 62, 86, 72, 1, 9, 79, 0, 52, 0, 62, 87, 72, 1, 9, 80, 0, 52, 0, 62, 88, 72, 1, 9, 81, 0, 52, 0, 62, 89, 72, 1, 9, 82, 0, 52, 0, 62, 90, 72, 1, 9, 83, 0, 0, 0, 92, 91, 84, 0, 0, 0, 0, 93, 93, -1, 29, 5, 1, 6, 2, 7, 2, 8, 3, 94, 85, 95, 86, 96, 87, 97, 88, 98, 89, 99, 89, 100, 89, 101, 89, 102, 1, 103, 1, 104, 90, 105, 2, 106, 5, 107, 91, 108, 2, 109, 92, 110, 5, 111, 3, 112, 3, 113, 93, 114, 94, 115, 94, 116, 1, 117, 3, 118, 95, 0 </int_array>
364+
<int_array len="708"> -1, -1, 1, 0, -1, 2, 2, 0, 3, 1, 0, 0, 0, 5, 4, -1, 16, 2, 0, 6, 2, 7, 3, 8, 3, 9, 4, 10, 5, 11, 6, 12, 7, 13, 8, 14, 9, 15, 10, 16, 11, 17, 3, 18, 6, 19, 12, 3, 13, 0, 0, 0, 1, 20, -1, 2, 2, 0, 3, 14, 0, 2, 0, 22, 21, 15, 1, 10, 16, 0, 2, 0, 22, 23, 15, 1, 10, 17, 0, 2, 0, 22, 24, 15, 1, 10, 18, 0, 2, 0, 22, 25, 15, 1, 10, 19, 0, 2, 0, 22, 26, 15, 1, 10, 20, 0, 2, 0, 22, 27, 15, 1, 10, 21, 0, 2, 0, 22, 28, 15, 1, 10, 22, 0, 2, 0, 22, 29, 15, 1, 10, 23, 0, 2, 0, 22, 30, 15, 1, 10, 24, 0, 2, 0, 22, 31, 15, 1, 10, 25, 0, 2, 0, 22, 32, 15, 1, 10, 26, 0, 2, 0, 22, 33, 15, 1, 10, 27, 0, 2, 0, 22, 34, 15, 1, 10, 28, 0, 2, 0, 22, 35, 15, 1, 10, 29, 0, 2, 0, 22, 36, 15, 1, 10, 30, 0, 2, 0, 22, 37, 15, 1, 10, 31, 0, 2, 0, 22, 38, 15, 1, 10, 32, 0, 2, 0, 22, 39, 15, 1, 10, 33, 0, 2, 0, 22, 40, 15, 1, 10, 34, 0, 2, 0, 22, 41, 15, 1, 10, 35, 0, 2, 0, 22, 42, 15, 1, 10, 36, 0, 2, 0, 22, 43, 15, 1, 10, 37, 0, 2, 0, 22, 44, 15, 1, 10, 38, 0, 2, 0, 22, 45, 15, 1, 10, 39, 0, 2, 0, 22, 46, 15, 1, 10, 40, 0, 2, 0, 22, 47, 15, 1, 10, 41, 0, 2, 0, 22, 48, 15, 1, 10, 42, 0, 2, 0, 22, 49, 15, 1, 10, 43, 0, 2, 0, 22, 50, 15, 1, 10, 44, 0, 2, 0, 22, 51, 15, 1, 10, 45, 0, 2, 0, 22, 52, 15, 1, 10, 46, 0, 2, 0, 22, 53, 15, 1, 10, 47, 0, 2, 0, 22, 54, 15, 1, 10, 48, 0, 2, 0, 22, 55, 15, 1, 10, 49, 0, 2, 0, 22, 56, 15, 1, 10, 50, 0, 2, 0, 22, 57, 15, 1, 10, 51, 0, 2, 0, 22, 58, 15, 1, 10, 52, 0, 2, 0, 22, 59, 15, 1, 10, 53, 0, 2, 0, 22, 60, 15, 1, 10, 54, 0, 2, 0, 22, 61, 15, 1, 10, 55, 0, 2, 0, 22, 62, 15, 1, 10, 56, 0, 2, 0, 22, 63, 15, 1, 10, 57, 0, 0, 0, 65, 64, 58, 1, 10, 59, 0, 0, 0, 1, 66, -1, 1, 2, 0, 0, 46, 0, 68, 67, 60, 3, 10, 61, 69, 62, 70, 63, 0, 46, 0, 68, 71, 60, 3, 10, 64, 69, 65, 70, 66, 0, 46, 0, 68, 72, 60, 3, 10, 67, 69, 68, 70, 66, 0, 46, 0, 68, 73, 69, 1, 10, 70, 0, 0, 0, 75, 74, -1, 7, 2, 0, 76, 71, 77, 4, 78, 2, 79, 72, 80, 2, 81, 4, 0, 0, 0, 1, 82, -1, 1, 2, 0, 0, 52, 0, 65, 83, 73, 1, 10, 74, 0, 52, 0, 65, 84, 73, 1, 10, 75, 0, 52, 0, 65, 85, 73, 1, 10, 76, 0, 52, 0, 65, 86, 73, 1, 10, 77, 0, 52, 0, 65, 87, 73, 1, 10, 78, 0, 52, 0, 65, 88, 73, 1, 10, 79, 0, 52, 0, 65, 89, 73, 1, 10, 80, 0, 52, 0, 65, 90, 73, 1, 10, 81, 0, 52, 0, 65, 91, 73, 1, 10, 82, 0, 52, 0, 65, 92, 73, 1, 10, 83, 0, 52, 0, 65, 93, 73, 1, 10, 84, 0, 0, 0, 95, 94, 85, 0, 0, 0, 0, 96, 96, -1, 30, 2, 0, 6, 2, 7, 3, 8, 3, 9, 4, 97, 86, 98, 87, 99, 88, 100, 89, 101, 0, 102, 0, 103, 0, 104, 0, 105, 2, 106, 2, 107, 90, 108, 3, 109, 6, 110, 91, 111, 3, 112, 92, 113, 6, 114, 4, 115, 4, 116, 93, 117, 94, 118, 94, 119, 2, 120, 4, 121, 95, 0 </int_array>
362365
<string> "conns" </string>
363366
<int_array len="0"> </int_array>
364367
</dictionary>

demos/3d/kinematic_char/cubelib.res

11.2 KB
Binary file not shown.

demos/3d/kinematic_char/cubio.gd

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
extends KinematicBody
3+
4+
# member variables here, example:
5+
# var a=2
6+
# var b="textvar"
7+
8+
var g = -9.8
9+
var vel = Vector3()
10+
const MAX_SPEED = 5
11+
const JUMP_SPEED = 7
12+
const ACCEL= 2
13+
const DEACCEL= 4
14+
const MAX_SLOPE_ANGLE = 30
15+
16+
func _fixed_process(delta):
17+
18+
var dir = Vector3() #where does the player intend to walk to
19+
var cam_xform = get_node("target/camera").get_global_transform()
20+
21+
if (Input.is_action_pressed("move_forward")):
22+
dir+=-cam_xform.basis[2]
23+
if (Input.is_action_pressed("move_backwards")):
24+
dir+=cam_xform.basis[2]
25+
if (Input.is_action_pressed("move_left")):
26+
dir+=-cam_xform.basis[0]
27+
if (Input.is_action_pressed("move_right")):
28+
dir+=cam_xform.basis[0]
29+
30+
dir.y=0
31+
dir=dir.normalized()
32+
33+
vel.y+=delta*g
34+
35+
var hvel = vel
36+
hvel.y=0
37+
38+
var target = dir*MAX_SPEED
39+
var accel
40+
if (dir.dot(hvel) >0):
41+
accel=ACCEL
42+
else:
43+
accel=DEACCEL
44+
45+
hvel = hvel.linear_interpolate(target,accel*delta)
46+
47+
vel.x=hvel.x;
48+
vel.z=hvel.z
49+
50+
var motion = vel*delta
51+
motion=move(vel*delta)
52+
53+
var on_floor = false
54+
var original_vel = vel
55+
56+
57+
var floor_velocity=Vector2()
58+
59+
var attempts=4
60+
61+
while(is_colliding() and attempts):
62+
var n=get_collision_normal()
63+
64+
if ( rad2deg(acos(n.dot( Vector3(0,1,0)))) < MAX_SLOPE_ANGLE ):
65+
#if angle to the "up" vectors is < angle tolerance
66+
#char is on floor
67+
floor_velocity=get_collider_velocity()
68+
on_floor=true
69+
70+
motion = n.slide(motion)
71+
vel = n.slide(vel)
72+
if (original_vel.dot(vel) > 0):
73+
#do not allow to slide towads the opposite direction we were coming from
74+
motion=move(motion)
75+
if (motion.length()<0.001):
76+
break
77+
attempts-=1
78+
79+
if (on_floor and floor_velocity!=Vector3()):
80+
move(floor_velocity*delta)
81+
82+
if (on_floor and Input.is_action_pressed("jump")):
83+
vel.y=JUMP_SPEED
84+
85+
var crid = get_node("../elevator1").get_rid()
86+
# print(crid," : ",PS.body_get_state(crid,PS.BODY_STATE_TRANSFORM))
87+
88+
func _ready():
89+
# Initalization here
90+
set_fixed_process(true)
91+
pass
92+
93+
94+
func _on_tcube_body_enter( body ):
95+
get_node("../ty").show()
96+
pass # replace with function body

demos/3d/kinematic_char/engine.cfg

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[application]
2+
3+
name="Kinematic Character 3D"
4+
main_scene="res://level.scn"
5+
icon="res://kinebody3d.png"
6+
7+
[input]
8+
9+
move_forward=[key(Up)]
10+
move_left=[key(Left)]
11+
move_right=[key(Right)]
12+
move_backwards=[key(Down)]
13+
jump=[key(Space)]
14+
15+
[rasterizer]
16+
17+
shadow_filter=3

0 commit comments

Comments
 (0)