summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
Diffstat (limited to 'servers')
-rw-r--r--servers/physics/collision_solver_sw.cpp4
-rw-r--r--servers/physics/shape_sw.cpp16
-rw-r--r--servers/physics/shape_sw.h4
-rw-r--r--servers/physics_2d/collision_solver_2d_sw.cpp4
-rw-r--r--servers/physics_2d/shape_2d_sw.cpp9
-rw-r--r--servers/physics_2d/shape_2d_sw.h2
6 files changed, 33 insertions, 6 deletions
diff --git a/servers/physics/collision_solver_sw.cpp b/servers/physics/collision_solver_sw.cpp
index e26a7a4d89..0037b9a862 100644
--- a/servers/physics/collision_solver_sw.cpp
+++ b/servers/physics/collision_solver_sw.cpp
@@ -90,6 +90,10 @@ bool CollisionSolverSW::solve_ray(const ShapeSW *p_shape_A, const Transform &p_t
return false;
Vector3 support_B = p_transform_B.xform(p);
+ if (ray->get_slips_on_slope()) {
+ Vector3 global_n = ai.basis.xform_inv(n).normalized();
+ support_B = support_A + (support_B - support_A).length() * global_n;
+ }
if (p_result_callback) {
if (p_swap_result)
diff --git a/servers/physics/shape_sw.cpp b/servers/physics/shape_sw.cpp
index 5a58742958..5ff50948ba 100644
--- a/servers/physics/shape_sw.cpp
+++ b/servers/physics/shape_sw.cpp
@@ -165,6 +165,10 @@ real_t RayShapeSW::get_length() const {
return length;
}
+bool RayShapeSW::get_slips_on_slope() const {
+ return slips_on_slope;
+}
+
void RayShapeSW::project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const {
// don't think this will be even used
@@ -221,25 +225,31 @@ Vector3 RayShapeSW::get_moment_of_inertia(real_t p_mass) const {
return Vector3();
}
-void RayShapeSW::_setup(real_t p_length) {
+void RayShapeSW::_setup(real_t p_length, bool p_slips_on_slope) {
length = p_length;
+ slips_on_slope = p_slips_on_slope;
configure(AABB(Vector3(0, 0, 0), Vector3(0.1, 0.1, length)));
}
void RayShapeSW::set_data(const Variant &p_data) {
- _setup(p_data);
+ Dictionary d = p_data;
+ _setup(d["length"], d["slips_on_slope"]);
}
Variant RayShapeSW::get_data() const {
- return length;
+ Dictionary d;
+ d["length"] = length;
+ d["slips_on_slope"] = slips_on_slope;
+ return d;
}
RayShapeSW::RayShapeSW() {
length = 1;
+ slips_on_slope = false;
}
/********** SPHERE *************/
diff --git a/servers/physics/shape_sw.h b/servers/physics/shape_sw.h
index 4a9a6289ff..7f7f9f4f98 100644
--- a/servers/physics/shape_sw.h
+++ b/servers/physics/shape_sw.h
@@ -149,11 +149,13 @@ public:
class RayShapeSW : public ShapeSW {
real_t length;
+ bool slips_on_slope;
- void _setup(real_t p_length);
+ void _setup(real_t p_length, bool p_slips_on_slope);
public:
real_t get_length() const;
+ bool get_slips_on_slope() const;
virtual real_t get_area() const { return 0.0; }
virtual PhysicsServer::ShapeType get_type() const { return PhysicsServer::SHAPE_RAY; }
diff --git a/servers/physics_2d/collision_solver_2d_sw.cpp b/servers/physics_2d/collision_solver_2d_sw.cpp
index a6ef110149..efee98a35a 100644
--- a/servers/physics_2d/collision_solver_2d_sw.cpp
+++ b/servers/physics_2d/collision_solver_2d_sw.cpp
@@ -95,6 +95,10 @@ bool CollisionSolver2DSW::solve_raycast(const Shape2DSW *p_shape_A, const Transf
}
Vector2 support_B = p_transform_B.xform(p);
+ if (ray->get_slips_on_slope()) {
+ Vector2 global_n = invb.basis_xform_inv(n).normalized();
+ support_B = support_A + (support_B - support_A).length() * global_n;
+ }
if (p_result_callback) {
if (p_swap_result)
diff --git a/servers/physics_2d/shape_2d_sw.cpp b/servers/physics_2d/shape_2d_sw.cpp
index 4605516fe0..abd513d936 100644
--- a/servers/physics_2d/shape_2d_sw.cpp
+++ b/servers/physics_2d/shape_2d_sw.cpp
@@ -184,13 +184,18 @@ real_t RayShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2 &p_scale)
void RayShape2DSW::set_data(const Variant &p_data) {
- length = p_data;
+ Dictionary d = p_data;
+ length = d["length"];
+ slips_on_slope = d["slips_on_slope"];
configure(Rect2(0, 0, 0.001, length));
}
Variant RayShape2DSW::get_data() const {
- return length;
+ Dictionary d;
+ d["length"] = length;
+ d["slips_on_slope"] = slips_on_slope;
+ return d;
}
/*********************************************************/
diff --git a/servers/physics_2d/shape_2d_sw.h b/servers/physics_2d/shape_2d_sw.h
index c4c267b368..d937301f3c 100644
--- a/servers/physics_2d/shape_2d_sw.h
+++ b/servers/physics_2d/shape_2d_sw.h
@@ -197,9 +197,11 @@ public:
class RayShape2DSW : public Shape2DSW {
real_t length;
+ bool slips_on_slope;
public:
_FORCE_INLINE_ real_t get_length() const { return length; }
+ _FORCE_INLINE_ bool get_slips_on_slope() const { return slips_on_slope; }
virtual Physics2DServer::ShapeType get_type() const { return Physics2DServer::SHAPE_RAY; }