summaryrefslogtreecommitdiff
path: root/servers/physics_2d
diff options
context:
space:
mode:
authorAndrea Catania <info@andreacatania.com>2018-02-19 20:59:57 +0100
committerAndrea Catania <info@andreacatania.com>2018-02-19 20:59:57 +0100
commitffc3ef86778f486823bedf66cc5a937fc09abe6a (patch)
tree15581f9cc2b0fedbacf20dbf989700682f6661c0 /servers/physics_2d
parentcbdd410a6f476503ee4bc27ac2f475a73960236d (diff)
Improved ray shape (2D and 3D) by addiing the possibility to act as regular shape
Diffstat (limited to 'servers/physics_2d')
-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
3 files changed, 13 insertions, 2 deletions
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; }