summaryrefslogtreecommitdiff
path: root/servers/physics_3d
diff options
context:
space:
mode:
Diffstat (limited to 'servers/physics_3d')
-rw-r--r--servers/physics_3d/godot_area_3d.cpp25
-rw-r--r--servers/physics_3d/godot_area_3d.h10
-rw-r--r--servers/physics_3d/godot_collision_solver_3d.cpp5
3 files changed, 15 insertions, 25 deletions
diff --git a/servers/physics_3d/godot_area_3d.cpp b/servers/physics_3d/godot_area_3d.cpp
index cd1f3b52b9..5bf16aa688 100644
--- a/servers/physics_3d/godot_area_3d.cpp
+++ b/servers/physics_3d/godot_area_3d.cpp
@@ -152,11 +152,8 @@ void GodotArea3D::set_param(PhysicsServer3D::AreaParameter p_param, const Varian
case PhysicsServer3D::AREA_PARAM_GRAVITY_IS_POINT:
gravity_is_point = p_value;
break;
- case PhysicsServer3D::AREA_PARAM_GRAVITY_DISTANCE_SCALE:
- gravity_distance_scale = p_value;
- break;
- case PhysicsServer3D::AREA_PARAM_GRAVITY_POINT_ATTENUATION:
- point_attenuation = p_value;
+ case PhysicsServer3D::AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE:
+ gravity_point_unit_distance = p_value;
break;
case PhysicsServer3D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE:
_set_space_override_mode(linear_damping_override_mode, (PhysicsServer3D::AreaSpaceOverrideMode)(int)p_value);
@@ -200,10 +197,8 @@ Variant GodotArea3D::get_param(PhysicsServer3D::AreaParameter p_param) const {
return gravity_vector;
case PhysicsServer3D::AREA_PARAM_GRAVITY_IS_POINT:
return gravity_is_point;
- case PhysicsServer3D::AREA_PARAM_GRAVITY_DISTANCE_SCALE:
- return gravity_distance_scale;
- case PhysicsServer3D::AREA_PARAM_GRAVITY_POINT_ATTENUATION:
- return point_attenuation;
+ case PhysicsServer3D::AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE:
+ return gravity_point_unit_distance;
case PhysicsServer3D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE:
return linear_damping_override_mode;
case PhysicsServer3D::AREA_PARAM_LINEAR_DAMP:
@@ -333,13 +328,13 @@ void GodotArea3D::call_queries() {
void GodotArea3D::compute_gravity(const Vector3 &p_position, Vector3 &r_gravity) const {
if (is_gravity_point()) {
- const real_t gr_distance_scale = get_gravity_distance_scale();
+ const real_t gr_unit_dist = get_gravity_point_unit_distance();
Vector3 v = get_transform().xform(get_gravity_vector()) - p_position;
- if (gr_distance_scale > 0) {
- const real_t v_length = v.length();
- if (v_length > 0) {
- const real_t v_scaled = v_length * gr_distance_scale;
- r_gravity = (v.normalized() * (get_gravity() / (v_scaled * v_scaled)));
+ if (gr_unit_dist > 0) {
+ const real_t v_length_sq = v.length_squared();
+ if (v_length_sq > 0) {
+ const real_t gravity_strength = get_gravity() * gr_unit_dist * gr_unit_dist / v_length_sq;
+ r_gravity = v.normalized() * gravity_strength;
} else {
r_gravity = Vector3();
}
diff --git a/servers/physics_3d/godot_area_3d.h b/servers/physics_3d/godot_area_3d.h
index 0961da5b7d..f05d0f9019 100644
--- a/servers/physics_3d/godot_area_3d.h
+++ b/servers/physics_3d/godot_area_3d.h
@@ -49,8 +49,7 @@ class GodotArea3D : public GodotCollisionObject3D {
real_t gravity = 9.80665;
Vector3 gravity_vector = Vector3(0, -1, 0);
bool gravity_is_point = false;
- real_t gravity_distance_scale = 0.0;
- real_t point_attenuation = 1.0;
+ real_t gravity_point_unit_distance = 0.0;
real_t linear_damp = 0.1;
real_t angular_damp = 0.1;
real_t wind_force_magnitude = 0.0;
@@ -134,11 +133,8 @@ public:
_FORCE_INLINE_ void set_gravity_as_point(bool p_enable) { gravity_is_point = p_enable; }
_FORCE_INLINE_ bool is_gravity_point() const { return gravity_is_point; }
- _FORCE_INLINE_ void set_gravity_distance_scale(real_t scale) { gravity_distance_scale = scale; }
- _FORCE_INLINE_ real_t get_gravity_distance_scale() const { return gravity_distance_scale; }
-
- _FORCE_INLINE_ void set_point_attenuation(real_t p_point_attenuation) { point_attenuation = p_point_attenuation; }
- _FORCE_INLINE_ real_t get_point_attenuation() const { return point_attenuation; }
+ _FORCE_INLINE_ void set_gravity_point_unit_distance(real_t scale) { gravity_point_unit_distance = scale; }
+ _FORCE_INLINE_ real_t get_gravity_point_unit_distance() const { return gravity_point_unit_distance; }
_FORCE_INLINE_ void set_linear_damp(real_t p_linear_damp) { linear_damp = p_linear_damp; }
_FORCE_INLINE_ real_t get_linear_damp() const { return linear_damp; }
diff --git a/servers/physics_3d/godot_collision_solver_3d.cpp b/servers/physics_3d/godot_collision_solver_3d.cpp
index fb5a67c008..2de1d86de1 100644
--- a/servers/physics_3d/godot_collision_solver_3d.cpp
+++ b/servers/physics_3d/godot_collision_solver_3d.cpp
@@ -127,11 +127,10 @@ bool GodotCollisionSolver3D::solve_separation_ray(const GodotShape3D *p_shape_A,
}
if (p_result_callback) {
+ Vector3 normal = (support_B - support_A).normalized();
if (p_swap_result) {
- Vector3 normal = (support_B - support_A).normalized();
- p_result_callback(support_B, 0, support_A, 0, normal, p_userdata);
+ p_result_callback(support_B, 0, support_A, 0, -normal, p_userdata);
} else {
- Vector3 normal = (support_A - support_B).normalized();
p_result_callback(support_A, 0, support_B, 0, normal, p_userdata);
}
}