diff options
Diffstat (limited to 'scene/3d')
-rw-r--r-- | scene/3d/physics_body.cpp | 15 | ||||
-rw-r--r-- | scene/3d/physics_body.h | 2 | ||||
-rw-r--r-- | scene/3d/physics_joint.cpp | 31 | ||||
-rw-r--r-- | scene/3d/physics_joint.h | 4 | ||||
-rw-r--r-- | scene/3d/spatial.cpp | 10 | ||||
-rw-r--r-- | scene/3d/spatial.h | 1 |
6 files changed, 49 insertions, 14 deletions
diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index d61859a3d0..de50484a1e 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -1073,7 +1073,7 @@ Vector3 KinematicBody::move_to(const Vector3& p_position) { return move(p_position-get_global_transform().origin); } -bool KinematicBody::can_move_to(const Vector3& p_position, bool p_discrete) { +bool KinematicBody::can_teleport_to(const Vector3& p_position) { ERR_FAIL_COND_V(!is_inside_tree(),false); PhysicsDirectSpaceState *dss = PhysicsServer::get_singleton()->space_get_direct_state(get_world()->get_space()); @@ -1089,25 +1089,18 @@ bool KinematicBody::can_move_to(const Vector3& p_position, bool p_discrete) { if (collide_character) mask|=PhysicsDirectSpaceState::TYPE_MASK_CHARACTER_BODY; - Vector3 motion = p_position-get_global_transform().origin; Transform xform=get_global_transform(); - - if (true || p_discrete) { - - xform.origin+=motion; - motion=Vector3(); - } + xform.origin=p_position; Set<RID> exclude; exclude.insert(get_rid()); - //fill exclude list.. for(int i=0;i<get_shape_count();i++) { if (is_shape_set_as_trigger(i)) continue; - bool col = dss->intersect_shape(get_shape(i)->get_rid(), xform * get_shape_transform(i),0,NULL,0,exclude,get_layer_mask(),mask); + bool col = dss->intersect_shape(get_shape(i)->get_rid(), xform * get_shape_transform(i),0,NULL,1,exclude,get_layer_mask(),mask); if (col) return false; } @@ -1205,7 +1198,7 @@ void KinematicBody::_bind_methods() { ObjectTypeDB::bind_method(_MD("move","rel_vec"),&KinematicBody::move); ObjectTypeDB::bind_method(_MD("move_to","position"),&KinematicBody::move_to); - ObjectTypeDB::bind_method(_MD("can_move_to","position"),&KinematicBody::can_move_to); + ObjectTypeDB::bind_method(_MD("can_teleport_to","position"),&KinematicBody::can_teleport_to); ObjectTypeDB::bind_method(_MD("is_colliding"),&KinematicBody::is_colliding); diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h index 66490ba925..0e63b77118 100644 --- a/scene/3d/physics_body.h +++ b/scene/3d/physics_body.h @@ -304,7 +304,7 @@ public: Vector3 move(const Vector3& p_motion); Vector3 move_to(const Vector3& p_position); - bool can_move_to(const Vector3& p_position,bool p_discrete=false); + bool can_teleport_to(const Vector3& p_position); bool is_colliding() const; Vector3 get_collision_pos() const; Vector3 get_collision_normal() const; diff --git a/scene/3d/physics_joint.cpp b/scene/3d/physics_joint.cpp index 0cc72b28e5..f4facb7c3f 100644 --- a/scene/3d/physics_joint.cpp +++ b/scene/3d/physics_joint.cpp @@ -34,8 +34,15 @@ void Joint::_update_joint(bool p_only_free) { if (joint.is_valid()) { - if (ba.is_valid() && bb.is_valid()) - PhysicsServer::get_singleton()->body_remove_collision_exception(ba,bb); + if (ba.is_valid() && bb.is_valid()) { + + if (exclude_from_collision) + PhysicsServer::get_singleton()->body_add_collision_exception(ba,bb); + else + PhysicsServer::get_singleton()->body_remove_collision_exception(ba,bb); + + } + PhysicsServer::get_singleton()->free(joint); joint=RID(); ba=RID(); @@ -144,6 +151,19 @@ void Joint::_notification(int p_what) { } +void Joint::set_exclude_nodes_from_collision(bool p_enable) { + + if (exclude_from_collision==p_enable) + return; + exclude_from_collision=p_enable; + _update_joint(); +} + +bool Joint::get_exclude_nodes_from_collision() const{ + + return exclude_from_collision; +} + void Joint::_bind_methods() { @@ -156,10 +176,16 @@ void Joint::_bind_methods() { ObjectTypeDB::bind_method( _MD("set_solver_priority","priority"), &Joint::set_solver_priority ); ObjectTypeDB::bind_method( _MD("get_solver_priority"), &Joint::get_solver_priority ); + ObjectTypeDB::bind_method( _MD("set_exclude_nodes_from_collision","enable"), &Joint::set_exclude_nodes_from_collision ); + ObjectTypeDB::bind_method( _MD("get_exclude_nodes_from_collision"), &Joint::get_exclude_nodes_from_collision ); + ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "nodes/node_a"), _SCS("set_node_a"),_SCS("get_node_a") ); ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "nodes/node_b"), _SCS("set_node_b"),_SCS("get_node_b") ); ADD_PROPERTY( PropertyInfo( Variant::INT, "solver/priority",PROPERTY_HINT_RANGE,"1,8,1"), _SCS("set_solver_priority"),_SCS("get_solver_priority") ); + ADD_PROPERTY( PropertyInfo( Variant::BOOL, "collision/exclude_nodes"), _SCS("set_exclude_nodes_from_collision"),_SCS("get_exclude_nodes_from_collision") ); + + } @@ -167,6 +193,7 @@ void Joint::_bind_methods() { Joint::Joint() { + exclude_from_collision=true; solver_priority=1; } diff --git a/scene/3d/physics_joint.h b/scene/3d/physics_joint.h index a5f4ea4bdb..3f5a0e91a6 100644 --- a/scene/3d/physics_joint.h +++ b/scene/3d/physics_joint.h @@ -45,6 +45,7 @@ class Joint : public Spatial { NodePath b; int solver_priority; + bool exclude_from_collision; protected: @@ -67,6 +68,9 @@ public: void set_solver_priority(int p_priority); int get_solver_priority() const; + void set_exclude_nodes_from_collision(bool p_enable); + bool get_exclude_nodes_from_collision() const; + RID get_joint() const { return joint; } Joint(); diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index a65f68ed2c..7d48420a83 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -594,6 +594,15 @@ bool Spatial::is_hidden() const{ return !data.visible; } +void Spatial::set_hidden(bool p_hidden) { + + if (data.visible != p_hidden) { + return; + } + + _set_visible_(!p_hidden); +} + void Spatial::_set_visible_(bool p_visible) { if (p_visible) @@ -742,6 +751,7 @@ void Spatial::_bind_methods() { ObjectTypeDB::bind_method(_MD("hide"), &Spatial::hide); ObjectTypeDB::bind_method(_MD("is_visible"), &Spatial::is_visible); ObjectTypeDB::bind_method(_MD("is_hidden"), &Spatial::is_hidden); + ObjectTypeDB::bind_method(_MD("set_hidden","hidden"), &Spatial::set_hidden); ObjectTypeDB::bind_method(_MD("_set_visible_"), &Spatial::_set_visible_); ObjectTypeDB::bind_method(_MD("_is_visible_"), &Spatial::_is_visible_); diff --git a/scene/3d/spatial.h b/scene/3d/spatial.h index 7fa6099d7a..b1e3a82868 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/spatial.h @@ -191,6 +191,7 @@ public: void hide(); bool is_visible() const; bool is_hidden() const; + void set_hidden(bool p_hidden); #ifdef TOOLS_ENABLED void set_import_transform(const Transform& p_transform) ; |