mirror of
https://github.com/godotengine/godot
synced 2024-09-05 11:18:27 +00:00
Replace Area gravity point distance scale with unit distance
This commit is contained in:
parent
866e2b95dc
commit
79215131b5
|
@ -87,8 +87,9 @@
|
|||
<member name="gravity_point_center" type="Vector2" setter="set_gravity_point_center" getter="get_gravity_point_center" default="Vector2(0, 1)">
|
||||
If gravity is a point (see [member gravity_point]), this will be the point of attraction.
|
||||
</member>
|
||||
<member name="gravity_point_distance_scale" type="float" setter="set_gravity_point_distance_scale" getter="get_gravity_point_distance_scale" default="0.0">
|
||||
The falloff factor for point gravity. The greater the value, the faster gravity decreases with distance.
|
||||
<member name="gravity_point_unit_distance" type="float" setter="set_gravity_point_unit_distance" getter="get_gravity_point_unit_distance" default="0.0">
|
||||
The distance at which the gravity strength is equal to [member gravity]. For example, on a planet 100 pixels in radius with a surface gravity of 4.0 px/s², set the [member gravity] to 4.0 and the unit distance to 100.0. The gravity will have falloff according to the inverse square law, so in the example, at 200 pixels from the center the gravity will be 1.0 px/s² (twice the distance, 1/4th the gravity), at 50 pixels it will be 16.0 px/s² (half the distance, 4x the gravity), and so on.
|
||||
The above is true only when the unit distance is a positive number. When this is set to 0.0, the gravity will be constant regardless of distance.
|
||||
</member>
|
||||
<member name="gravity_space_override" type="int" setter="set_gravity_space_override_mode" getter="get_gravity_space_override_mode" enum="Area2D.SpaceOverride" default="0">
|
||||
Override mode for gravity calculations within this area. See [enum SpaceOverride] for possible values.
|
||||
|
|
|
@ -86,8 +86,9 @@
|
|||
<member name="gravity_point_center" type="Vector3" setter="set_gravity_point_center" getter="get_gravity_point_center" default="Vector3(0, -1, 0)">
|
||||
If gravity is a point (see [member gravity_point]), this will be the point of attraction.
|
||||
</member>
|
||||
<member name="gravity_point_distance_scale" type="float" setter="set_gravity_point_distance_scale" getter="get_gravity_point_distance_scale" default="0.0">
|
||||
The falloff factor for point gravity. The greater the value, the faster gravity decreases with distance.
|
||||
<member name="gravity_point_unit_distance" type="float" setter="set_gravity_point_unit_distance" getter="get_gravity_point_unit_distance" default="0.0">
|
||||
The distance at which the gravity strength is equal to [member gravity]. For example, on a planet 100 meters in radius with a surface gravity of 4.0 m/s², set the [member gravity] to 4.0 and the unit distance to 100.0. The gravity will have falloff according to the inverse square law, so in the example, at 200 meters from the center the gravity will be 1.0 m/s² (twice the distance, 1/4th the gravity), at 50 meters it will be 16.0 m/s² (half the distance, 4x the gravity), and so on.
|
||||
The above is true only when the unit distance is a positive number. When this is set to 0.0, the gravity will be constant regardless of distance.
|
||||
</member>
|
||||
<member name="gravity_space_override" type="int" setter="set_gravity_space_override_mode" getter="get_gravity_space_override_mode" enum="Area3D.SpaceOverride" default="0">
|
||||
Override mode for gravity calculations within this area. See [enum SpaceOverride] for possible values.
|
||||
|
|
|
@ -984,8 +984,9 @@
|
|||
<constant name="AREA_PARAM_GRAVITY_IS_POINT" value="3" enum="AreaParameter">
|
||||
Constant to set/get whether the gravity vector of an area is a direction, or a center point.
|
||||
</constant>
|
||||
<constant name="AREA_PARAM_GRAVITY_DISTANCE_SCALE" value="4" enum="AreaParameter">
|
||||
Constant to set/get the falloff factor for point gravity of an area. The greater this value is, the faster the strength of gravity decreases with the square of distance.
|
||||
<constant name="AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE" value="4" enum="AreaParameter">
|
||||
Constant to set/get the distance at which the gravity strength is equal to the gravity controlled by [constant AREA_PARAM_GRAVITY]. For example, on a planet 100 pixels in radius with a surface gravity of 4.0 px/s², set the gravity to 4.0 and the unit distance to 100.0. The gravity will have falloff according to the inverse square law, so in the example, at 200 pixels from the center the gravity will be 1.0 px/s² (twice the distance, 1/4th the gravity), at 50 pixels it will be 16.0 px/s² (half the distance, 4x the gravity), and so on.
|
||||
The above is true only when the unit distance is a positive number. When the unit distance is set to 0.0, the gravity will be constant regardless of distance.
|
||||
</constant>
|
||||
<constant name="AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE" value="5" enum="AreaParameter">
|
||||
Constant to set/get linear damping override mode in an area. See [enum AreaSpaceOverrideMode] for possible values.
|
||||
|
|
|
@ -1315,8 +1315,9 @@
|
|||
<constant name="AREA_PARAM_GRAVITY_IS_POINT" value="3" enum="AreaParameter">
|
||||
Constant to set/get whether the gravity vector of an area is a direction, or a center point.
|
||||
</constant>
|
||||
<constant name="AREA_PARAM_GRAVITY_DISTANCE_SCALE" value="4" enum="AreaParameter">
|
||||
Constant to set/get the falloff factor for point gravity of an area. The greater this value is, the faster the strength of gravity decreases with the square of distance.
|
||||
<constant name="AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE" value="4" enum="AreaParameter">
|
||||
Constant to set/get the distance at which the gravity strength is equal to the gravity controlled by [constant AREA_PARAM_GRAVITY]. For example, on a planet 100 meters in radius with a surface gravity of 4.0 m/s², set the gravity to 4.0 and the unit distance to 100.0. The gravity will have falloff according to the inverse square law, so in the example, at 200 meters from the center the gravity will be 1.0 m/s² (twice the distance, 1/4th the gravity), at 50 meters it will be 16.0 m/s² (half the distance, 4x the gravity), and so on.
|
||||
The above is true only when the unit distance is a positive number. When this is set to 0.0, the gravity will be constant regardless of distance.
|
||||
</constant>
|
||||
<constant name="AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE" value="5" enum="AreaParameter">
|
||||
Constant to set/get linear damping override mode in an area. See [enum AreaSpaceOverrideMode] for possible values.
|
||||
|
|
|
@ -311,8 +311,8 @@ static const char *gdscript_function_renames[][2] = {
|
|||
{ "get_font_types", "get_font_type_list" }, // Theme
|
||||
{ "get_frame_color", "get_color" }, // ColorRect
|
||||
{ "get_global_rate_scale", "get_playback_speed_scale" }, // AudioServer
|
||||
{ "get_gravity_distance_scale", "get_gravity_point_distance_scale" }, //Area2D
|
||||
{ "get_gravity_vector", "get_gravity_direction" }, //Area2D
|
||||
{ "get_gravity_distance_scale", "get_gravity_point_unit_distance" }, // Area(2D/3D)
|
||||
{ "get_gravity_vector", "get_gravity_direction" }, // Area(2D/3D)
|
||||
{ "get_h_scrollbar", "get_h_scroll_bar" }, //ScrollContainer
|
||||
{ "get_hand", "get_tracker_hand" }, // XRPositionalTracker
|
||||
{ "get_handle_name", "_get_handle_name" }, // EditorNode3DGizmo
|
||||
|
@ -509,8 +509,8 @@ static const char *gdscript_function_renames[][2] = {
|
|||
{ "set_follow_smoothing", "set_position_smoothing_speed" }, // Camera2D
|
||||
{ "set_frame_color", "set_color" }, // ColorRect
|
||||
{ "set_global_rate_scale", "set_playback_speed_scale" }, // AudioServer
|
||||
{ "set_gravity_distance_scale", "set_gravity_point_distance_scale" }, // Area2D
|
||||
{ "set_gravity_vector", "set_gravity_direction" }, // Area2D
|
||||
{ "set_gravity_distance_scale", "set_gravity_point_unit_distance" }, // Area(2D/3D)
|
||||
{ "set_gravity_vector", "set_gravity_direction" }, // Area(2D/3D)
|
||||
{ "set_h_drag_enabled", "set_drag_horizontal_enabled" }, // Camera2D
|
||||
{ "set_icon_align", "set_icon_alignment" }, // Button
|
||||
{ "set_interior_ambient", "set_ambient_color" }, // ReflectionProbe
|
||||
|
@ -1111,8 +1111,8 @@ static const char *gdscript_properties_renames[][2] = {
|
|||
{ "files_disabled", "file_disabled_color" }, // Theme
|
||||
{ "folder_icon_modulate", "folder_icon_color" }, // Theme
|
||||
{ "global_rate_scale", "playback_speed_scale" }, // AudioServer
|
||||
{ "gravity_distance_scale", "gravity_point_distance_scale" }, // Area2D
|
||||
{ "gravity_vec", "gravity_direction" }, // Area2D
|
||||
{ "gravity_distance_scale", "gravity_point_unit_distance" }, // Area(2D/3D)
|
||||
{ "gravity_vec", "gravity_direction" }, // Area(2D/3D)
|
||||
{ "hint_tooltip", "tooltip_text" }, // Control
|
||||
{ "hseparation", "h_separation" }, // Theme
|
||||
{ "icon_align", "icon_alignment" }, // Button
|
||||
|
|
|
@ -51,13 +51,13 @@ bool Area2D::is_gravity_a_point() const {
|
|||
return gravity_is_point;
|
||||
}
|
||||
|
||||
void Area2D::set_gravity_point_distance_scale(real_t p_scale) {
|
||||
gravity_distance_scale = p_scale;
|
||||
PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale);
|
||||
void Area2D::set_gravity_point_unit_distance(real_t p_scale) {
|
||||
gravity_point_unit_distance = p_scale;
|
||||
PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE, p_scale);
|
||||
}
|
||||
|
||||
real_t Area2D::get_gravity_point_distance_scale() const {
|
||||
return gravity_distance_scale;
|
||||
real_t Area2D::get_gravity_point_unit_distance() const {
|
||||
return gravity_point_unit_distance;
|
||||
}
|
||||
|
||||
void Area2D::set_gravity_point_center(const Vector2 &p_center) {
|
||||
|
@ -557,8 +557,8 @@ void Area2D::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_gravity_is_point", "enable"), &Area2D::set_gravity_is_point);
|
||||
ClassDB::bind_method(D_METHOD("is_gravity_a_point"), &Area2D::is_gravity_a_point);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_gravity_point_distance_scale", "distance_scale"), &Area2D::set_gravity_point_distance_scale);
|
||||
ClassDB::bind_method(D_METHOD("get_gravity_point_distance_scale"), &Area2D::get_gravity_point_distance_scale);
|
||||
ClassDB::bind_method(D_METHOD("set_gravity_point_unit_distance", "distance_scale"), &Area2D::set_gravity_point_unit_distance);
|
||||
ClassDB::bind_method(D_METHOD("get_gravity_point_unit_distance"), &Area2D::get_gravity_point_unit_distance);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_gravity_point_center", "center"), &Area2D::set_gravity_point_center);
|
||||
ClassDB::bind_method(D_METHOD("get_gravity_point_center"), &Area2D::get_gravity_point_center);
|
||||
|
@ -622,7 +622,7 @@ void Area2D::_bind_methods() {
|
|||
ADD_GROUP("Gravity", "gravity_");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "gravity_space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_gravity_space_override_mode", "get_gravity_space_override_mode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gravity_point", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_gravity_is_point", "is_gravity_a_point");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_point_distance_scale", PROPERTY_HINT_RANGE, "0,1024,0.001,or_greater,exp"), "set_gravity_point_distance_scale", "get_gravity_point_distance_scale");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_point_unit_distance", PROPERTY_HINT_RANGE, "0,1024,0.001,or_greater,exp,suffix:px"), "set_gravity_point_unit_distance", "get_gravity_point_unit_distance");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "gravity_point_center", PROPERTY_HINT_NONE, "suffix:px"), "set_gravity_point_center", "get_gravity_point_center");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "gravity_direction"), "set_gravity_direction", "get_gravity_direction");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity", PROPERTY_HINT_RANGE, U"-4096,4096,0.001,or_less,or_greater,suffix:px/s\u00B2"), "set_gravity", "get_gravity");
|
||||
|
|
|
@ -51,7 +51,7 @@ private:
|
|||
Vector2 gravity_vec;
|
||||
real_t gravity = 0.0;
|
||||
bool gravity_is_point = false;
|
||||
real_t gravity_distance_scale = 0.0;
|
||||
real_t gravity_point_unit_distance = 0.0;
|
||||
|
||||
SpaceOverride linear_damp_space_override = SPACE_OVERRIDE_DISABLED;
|
||||
SpaceOverride angular_damp_space_override = SPACE_OVERRIDE_DISABLED;
|
||||
|
@ -144,8 +144,8 @@ public:
|
|||
void set_gravity_is_point(bool p_enabled);
|
||||
bool is_gravity_a_point() const;
|
||||
|
||||
void set_gravity_point_distance_scale(real_t p_scale);
|
||||
real_t get_gravity_point_distance_scale() const;
|
||||
void set_gravity_point_unit_distance(real_t p_scale);
|
||||
real_t get_gravity_point_unit_distance() const;
|
||||
|
||||
void set_gravity_point_center(const Vector2 &p_center);
|
||||
const Vector2 &get_gravity_point_center() const;
|
||||
|
|
|
@ -51,13 +51,13 @@ bool Area3D::is_gravity_a_point() const {
|
|||
return gravity_is_point;
|
||||
}
|
||||
|
||||
void Area3D::set_gravity_point_distance_scale(real_t p_scale) {
|
||||
gravity_distance_scale = p_scale;
|
||||
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale);
|
||||
void Area3D::set_gravity_point_unit_distance(real_t p_scale) {
|
||||
gravity_point_unit_distance = p_scale;
|
||||
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE, p_scale);
|
||||
}
|
||||
|
||||
real_t Area3D::get_gravity_point_distance_scale() const {
|
||||
return gravity_distance_scale;
|
||||
real_t Area3D::get_gravity_point_unit_distance() const {
|
||||
return gravity_point_unit_distance;
|
||||
}
|
||||
|
||||
void Area3D::set_gravity_point_center(const Vector3 &p_center) {
|
||||
|
@ -655,8 +655,8 @@ void Area3D::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_gravity_is_point", "enable"), &Area3D::set_gravity_is_point);
|
||||
ClassDB::bind_method(D_METHOD("is_gravity_a_point"), &Area3D::is_gravity_a_point);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_gravity_point_distance_scale", "distance_scale"), &Area3D::set_gravity_point_distance_scale);
|
||||
ClassDB::bind_method(D_METHOD("get_gravity_point_distance_scale"), &Area3D::get_gravity_point_distance_scale);
|
||||
ClassDB::bind_method(D_METHOD("set_gravity_point_unit_distance", "distance_scale"), &Area3D::set_gravity_point_unit_distance);
|
||||
ClassDB::bind_method(D_METHOD("get_gravity_point_unit_distance"), &Area3D::get_gravity_point_unit_distance);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_gravity_point_center", "center"), &Area3D::set_gravity_point_center);
|
||||
ClassDB::bind_method(D_METHOD("get_gravity_point_center"), &Area3D::get_gravity_point_center);
|
||||
|
@ -741,7 +741,7 @@ void Area3D::_bind_methods() {
|
|||
ADD_GROUP("Gravity", "gravity_");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "gravity_space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_gravity_space_override_mode", "get_gravity_space_override_mode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gravity_point", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_gravity_is_point", "is_gravity_a_point");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_point_distance_scale", PROPERTY_HINT_RANGE, "0,1024,0.001,or_greater,exp"), "set_gravity_point_distance_scale", "get_gravity_point_distance_scale");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_point_unit_distance", PROPERTY_HINT_RANGE, "0,1024,0.001,or_greater,exp,suffix:m"), "set_gravity_point_unit_distance", "get_gravity_point_unit_distance");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "gravity_point_center", PROPERTY_HINT_NONE, "suffix:m"), "set_gravity_point_center", "get_gravity_point_center");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "gravity_direction"), "set_gravity_direction", "get_gravity_direction");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity", PROPERTY_HINT_RANGE, U"-32,32,0.001,or_less,or_greater,suffix:m/s\u00B2"), "set_gravity", "get_gravity");
|
||||
|
|
|
@ -51,7 +51,7 @@ private:
|
|||
Vector3 gravity_vec;
|
||||
real_t gravity = 0.0;
|
||||
bool gravity_is_point = false;
|
||||
real_t gravity_distance_scale = 0.0;
|
||||
real_t gravity_point_unit_distance = 0.0;
|
||||
|
||||
SpaceOverride linear_damp_space_override = SPACE_OVERRIDE_DISABLED;
|
||||
SpaceOverride angular_damp_space_override = SPACE_OVERRIDE_DISABLED;
|
||||
|
@ -155,8 +155,8 @@ public:
|
|||
void set_gravity_is_point(bool p_enabled);
|
||||
bool is_gravity_a_point() const;
|
||||
|
||||
void set_gravity_point_distance_scale(real_t p_scale);
|
||||
real_t get_gravity_point_distance_scale() const;
|
||||
void set_gravity_point_unit_distance(real_t p_scale);
|
||||
real_t get_gravity_point_unit_distance() const;
|
||||
|
||||
void set_gravity_point_center(const Vector3 &p_center);
|
||||
const Vector3 &get_gravity_point_center() const;
|
||||
|
|
|
@ -145,8 +145,8 @@ void GodotArea2D::set_param(PhysicsServer2D::AreaParameter p_param, const Varian
|
|||
case PhysicsServer2D::AREA_PARAM_GRAVITY_IS_POINT:
|
||||
gravity_is_point = p_value;
|
||||
break;
|
||||
case PhysicsServer2D::AREA_PARAM_GRAVITY_DISTANCE_SCALE:
|
||||
gravity_distance_scale = p_value;
|
||||
case PhysicsServer2D::AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE:
|
||||
gravity_point_unit_distance = p_value;
|
||||
break;
|
||||
case PhysicsServer2D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE:
|
||||
_set_space_override_mode(linear_damping_override_mode, (PhysicsServer2D::AreaSpaceOverrideMode)(int)p_value);
|
||||
|
@ -176,8 +176,8 @@ Variant GodotArea2D::get_param(PhysicsServer2D::AreaParameter p_param) const {
|
|||
return gravity_vector;
|
||||
case PhysicsServer2D::AREA_PARAM_GRAVITY_IS_POINT:
|
||||
return gravity_is_point;
|
||||
case PhysicsServer2D::AREA_PARAM_GRAVITY_DISTANCE_SCALE:
|
||||
return gravity_distance_scale;
|
||||
case PhysicsServer2D::AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE:
|
||||
return gravity_point_unit_distance;
|
||||
case PhysicsServer2D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE:
|
||||
return linear_damping_override_mode;
|
||||
case PhysicsServer2D::AREA_PARAM_LINEAR_DAMP:
|
||||
|
@ -299,13 +299,13 @@ void GodotArea2D::call_queries() {
|
|||
|
||||
void GodotArea2D::compute_gravity(const Vector2 &p_position, Vector2 &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();
|
||||
Vector2 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 = Vector2();
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class GodotArea2D : public GodotCollisionObject2D {
|
|||
real_t gravity = 9.80665;
|
||||
Vector2 gravity_vector = Vector2(0, -1);
|
||||
bool gravity_is_point = false;
|
||||
real_t gravity_distance_scale = 0.0;
|
||||
real_t gravity_point_unit_distance = 0.0;
|
||||
real_t linear_damp = 0.1;
|
||||
real_t angular_damp = 1.0;
|
||||
int priority = 0;
|
||||
|
@ -124,8 +124,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_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; }
|
||||
|
|
|
@ -152,8 +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;
|
||||
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);
|
||||
|
@ -197,8 +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_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:
|
||||
|
@ -328,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();
|
||||
}
|
||||
|
|
|
@ -49,7 +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 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;
|
||||
|
@ -133,8 +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_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; }
|
||||
|
|
|
@ -811,7 +811,7 @@ void PhysicsServer2D::_bind_methods() {
|
|||
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY);
|
||||
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_VECTOR);
|
||||
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_IS_POINT);
|
||||
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_DISTANCE_SCALE);
|
||||
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE);
|
||||
BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE);
|
||||
BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP);
|
||||
BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE);
|
||||
|
|
|
@ -286,7 +286,7 @@ public:
|
|||
AREA_PARAM_GRAVITY,
|
||||
AREA_PARAM_GRAVITY_VECTOR,
|
||||
AREA_PARAM_GRAVITY_IS_POINT,
|
||||
AREA_PARAM_GRAVITY_DISTANCE_SCALE,
|
||||
AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE,
|
||||
AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE,
|
||||
AREA_PARAM_LINEAR_DAMP,
|
||||
AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE,
|
||||
|
|
|
@ -976,7 +976,7 @@ void PhysicsServer3D::_bind_methods() {
|
|||
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY);
|
||||
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_VECTOR);
|
||||
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_IS_POINT);
|
||||
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_DISTANCE_SCALE);
|
||||
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE);
|
||||
BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE);
|
||||
BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP);
|
||||
BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE);
|
||||
|
|
|
@ -316,7 +316,7 @@ public:
|
|||
AREA_PARAM_GRAVITY,
|
||||
AREA_PARAM_GRAVITY_VECTOR,
|
||||
AREA_PARAM_GRAVITY_IS_POINT,
|
||||
AREA_PARAM_GRAVITY_DISTANCE_SCALE,
|
||||
AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE,
|
||||
AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE,
|
||||
AREA_PARAM_LINEAR_DAMP,
|
||||
AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE,
|
||||
|
|
Loading…
Reference in a new issue