summaryrefslogtreecommitdiff
path: root/scene/2d/physics_body_2d.cpp
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2018-08-07 15:31:26 -0300
committerGitHub <noreply@github.com>2018-08-07 15:31:26 -0300
commit14fd797c536a675c94c36a2b2b924ce0295f5d64 (patch)
tree9ac70ce41c656f726402187f0fd90e578036c3af /scene/2d/physics_body_2d.cpp
parente0456f7976832b9f17958e1e8e7c18379b19e382 (diff)
parent5e65e28eed1398cceb4b77cb99ba6578115953db (diff)
Merge pull request #20381 from AndreaCatania/phymat_2
Improved Physics material
Diffstat (limited to 'scene/2d/physics_body_2d.cpp')
-rw-r--r--scene/2d/physics_body_2d.cpp30
1 files changed, 12 insertions, 18 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index b3ff21457d..85bef4e7f5 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -197,9 +197,9 @@ void StaticBody2D::set_friction(real_t p_friction) {
if (physics_material_override.is_null()) {
physics_material_override.instance();
+ set_physics_material_override(physics_material_override);
}
physics_material_override->set_friction(p_friction);
- _reload_physics_characteristics();
}
real_t StaticBody2D::get_friction() const {
@@ -223,9 +223,9 @@ void StaticBody2D::set_bounce(real_t p_bounce) {
if (physics_material_override.is_null()) {
physics_material_override.instance();
+ set_physics_material_override(physics_material_override);
}
physics_material_override->set_bounce(p_bounce);
- _reload_physics_characteristics();
}
real_t StaticBody2D::get_bounce() const {
@@ -243,7 +243,8 @@ real_t StaticBody2D::get_bounce() const {
void StaticBody2D::set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override) {
if (physics_material_override.is_valid()) {
- physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics");
+ if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics"))
+ physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics");
}
physics_material_override = p_physics_material_override;
@@ -300,13 +301,9 @@ void StaticBody2D::_reload_physics_characteristics() {
if (physics_material_override.is_null()) {
Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, 0);
Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, 1);
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, Physics2DServer::COMBINE_MODE_INHERIT);
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, Physics2DServer::COMBINE_MODE_INHERIT);
} else {
- Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, physics_material_override->get_bounce());
- Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, physics_material_override->get_friction());
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, (Physics2DServer::CombineMode)physics_material_override->get_bounce_combine_mode());
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, (Physics2DServer::CombineMode)physics_material_override->get_friction_combine_mode());
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce());
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, physics_material_override->computed_friction());
}
}
@@ -625,9 +622,9 @@ void RigidBody2D::set_friction(real_t p_friction) {
if (physics_material_override.is_null()) {
physics_material_override.instance();
+ set_physics_material_override(physics_material_override);
}
physics_material_override->set_friction(p_friction);
- _reload_physics_characteristics();
}
real_t RigidBody2D::get_friction() const {
@@ -650,9 +647,9 @@ void RigidBody2D::set_bounce(real_t p_bounce) {
if (physics_material_override.is_null()) {
physics_material_override.instance();
+ set_physics_material_override(physics_material_override);
}
physics_material_override->set_bounce(p_bounce);
- _reload_physics_characteristics();
}
real_t RigidBody2D::get_bounce() const {
@@ -669,7 +666,8 @@ real_t RigidBody2D::get_bounce() const {
void RigidBody2D::set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override) {
if (physics_material_override.is_valid()) {
- physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics");
+ if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics"))
+ physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics");
}
physics_material_override = p_physics_material_override;
@@ -1116,13 +1114,9 @@ void RigidBody2D::_reload_physics_characteristics() {
if (physics_material_override.is_null()) {
Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, 0);
Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, 1);
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, Physics2DServer::COMBINE_MODE_INHERIT);
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, Physics2DServer::COMBINE_MODE_INHERIT);
} else {
- Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, physics_material_override->get_bounce());
- Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, physics_material_override->get_friction());
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, (Physics2DServer::CombineMode)physics_material_override->get_bounce_combine_mode());
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, (Physics2DServer::CombineMode)physics_material_override->get_friction_combine_mode());
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce());
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, physics_material_override->computed_friction());
}
}