mirror of
https://github.com/godotengine/godot.git
synced 2024-11-11 06:33:10 +00:00
Revert #53174 (applying the delta in move and collide), rename rec_vel to distance and improve the doc description
This commit is contained in:
parent
9df9dc77a3
commit
cc3c4d6323
@ -25,12 +25,12 @@
|
|||||||
</method>
|
</method>
|
||||||
<method name="move_and_collide">
|
<method name="move_and_collide">
|
||||||
<return type="KinematicCollision2D" />
|
<return type="KinematicCollision2D" />
|
||||||
<argument index="0" name="linear_velocity" type="Vector2" />
|
<argument index="0" name="distance" type="Vector2" />
|
||||||
<argument index="1" name="test_only" type="bool" default="false" />
|
<argument index="1" name="test_only" type="bool" default="false" />
|
||||||
<argument index="2" name="safe_margin" type="float" default="0.08" />
|
<argument index="2" name="safe_margin" type="float" default="0.08" />
|
||||||
<description>
|
<description>
|
||||||
Moves the body along the vector [code]linear_velocity[/code]. This method should be used in [method Node._physics_process] (or in a method called by [method Node._physics_process]), as it uses the physics step's [code]delta[/code] value automatically in calculations. Otherwise, the simulation will run at an incorrect speed.
|
Moves the body along the vector [code]distance[/code]. In order to be frame rate independent in [method Node._physics_process] or [method Node._process], [code]distance[/code] should be computed using [code]delta[/code].
|
||||||
The body will stop if it collides. Returns a [KinematicCollision2D], which contains information about the collision when stopped, or when touching another body along the motion.
|
Returns a [KinematicCollision2D], which contains information about the collision when stopped, or when touching another body along the motion.
|
||||||
If [code]test_only[/code] is [code]true[/code], the body does not move but the would-be collision information is given.
|
If [code]test_only[/code] is [code]true[/code], the body does not move but the would-be collision information is given.
|
||||||
[code]safe_margin[/code] is the extra margin used for collision recovery (see [member CharacterBody2D.collision/safe_margin] for more details).
|
[code]safe_margin[/code] is the extra margin used for collision recovery (see [member CharacterBody2D.collision/safe_margin] for more details).
|
||||||
</description>
|
</description>
|
||||||
@ -45,12 +45,12 @@
|
|||||||
<method name="test_move">
|
<method name="test_move">
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<argument index="0" name="from" type="Transform2D" />
|
<argument index="0" name="from" type="Transform2D" />
|
||||||
<argument index="1" name="linear_velocity" type="Vector2" />
|
<argument index="1" name="distance" type="Vector2" />
|
||||||
<argument index="2" name="collision" type="KinematicCollision2D" default="null" />
|
<argument index="2" name="collision" type="KinematicCollision2D" default="null" />
|
||||||
<argument index="3" name="safe_margin" type="float" default="0.08" />
|
<argument index="3" name="safe_margin" type="float" default="0.08" />
|
||||||
<description>
|
<description>
|
||||||
Checks for collisions without moving the body. This method should be used in [method Node._physics_process] (or in a method called by [method Node._physics_process]), as it uses the physics step's [code]delta[/code] value automatically in calculations. Otherwise, the simulation will run at an incorrect speed.
|
Checks for collisions without moving the body. In order to be frame rate independent in [method Node._physics_process] or [method Node._process], [code]distance[/code] should be computed using [code]delta[/code].
|
||||||
Virtually sets the node's position, scale and rotation to that of the given [Transform2D], then tries to move the body along the vector [code]linear_velocity[/code]. Returns [code]true[/code] if a collision would stop the body from moving along the whole path.
|
Virtually sets the node's position, scale and rotation to that of the given [Transform2D], then tries to move the body along the vector [code]distance[/code]. Returns [code]true[/code] if a collision would stop the body from moving along the whole path.
|
||||||
[code]collision[/code] is an optional object of type [KinematicCollision2D], which contains additional information about the collision when stopped, or when touching another body along the motion.
|
[code]collision[/code] is an optional object of type [KinematicCollision2D], which contains additional information about the collision when stopped, or when touching another body along the motion.
|
||||||
[code]safe_margin[/code] is the extra margin used for collision recovery (see [member CharacterBody2D.collision/safe_margin] for more details).
|
[code]safe_margin[/code] is the extra margin used for collision recovery (see [member CharacterBody2D.collision/safe_margin] for more details).
|
||||||
</description>
|
</description>
|
||||||
|
@ -32,12 +32,12 @@
|
|||||||
</method>
|
</method>
|
||||||
<method name="move_and_collide">
|
<method name="move_and_collide">
|
||||||
<return type="KinematicCollision3D" />
|
<return type="KinematicCollision3D" />
|
||||||
<argument index="0" name="linear_velocity" type="Vector3" />
|
<argument index="0" name="distance" type="Vector3" />
|
||||||
<argument index="1" name="test_only" type="bool" default="false" />
|
<argument index="1" name="test_only" type="bool" default="false" />
|
||||||
<argument index="2" name="safe_margin" type="float" default="0.001" />
|
<argument index="2" name="safe_margin" type="float" default="0.001" />
|
||||||
<argument index="3" name="max_collisions" type="int" default="1" />
|
<argument index="3" name="max_collisions" type="int" default="1" />
|
||||||
<description>
|
<description>
|
||||||
Moves the body along the vector [code]linear_velocity[/code]. This method should be used in [method Node._physics_process] (or in a method called by [method Node._physics_process]), as it uses the physics step's [code]delta[/code] value automatically in calculations. Otherwise, the simulation will run at an incorrect speed.
|
Moves the body along the vector [code]distance[/code]. In order to be frame rate independent in [method Node._physics_process] or [method Node._process], [code]distance[/code] should be computed using [code]delta[/code].
|
||||||
The body will stop if it collides. Returns a [KinematicCollision3D], which contains information about the collision when stopped, or when touching another body along the motion.
|
The body will stop if it collides. Returns a [KinematicCollision3D], which contains information about the collision when stopped, or when touching another body along the motion.
|
||||||
If [code]test_only[/code] is [code]true[/code], the body does not move but the would-be collision information is given.
|
If [code]test_only[/code] is [code]true[/code], the body does not move but the would-be collision information is given.
|
||||||
[code]safe_margin[/code] is the extra margin used for collision recovery (see [member CharacterBody3D.collision/safe_margin] for more details).
|
[code]safe_margin[/code] is the extra margin used for collision recovery (see [member CharacterBody3D.collision/safe_margin] for more details).
|
||||||
@ -62,13 +62,13 @@
|
|||||||
<method name="test_move">
|
<method name="test_move">
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<argument index="0" name="from" type="Transform3D" />
|
<argument index="0" name="from" type="Transform3D" />
|
||||||
<argument index="1" name="linear_velocity" type="Vector3" />
|
<argument index="1" name="distance" type="Vector3" />
|
||||||
<argument index="2" name="collision" type="KinematicCollision3D" default="null" />
|
<argument index="2" name="collision" type="KinematicCollision3D" default="null" />
|
||||||
<argument index="3" name="safe_margin" type="float" default="0.001" />
|
<argument index="3" name="safe_margin" type="float" default="0.001" />
|
||||||
<argument index="4" name="max_collisions" type="int" default="1" />
|
<argument index="4" name="max_collisions" type="int" default="1" />
|
||||||
<description>
|
<description>
|
||||||
Checks for collisions without moving the body. This method should be used in [method Node._physics_process] (or in a method called by [method Node._physics_process]), as it uses the physics step's [code]delta[/code] value automatically in calculations. Otherwise, the simulation will run at an incorrect speed.
|
Checks for collisions without moving the body. In order to be frame rate independent in [method Node._physics_process] or [method Node._process], [code]distance[/code] should be computed using [code]delta[/code].
|
||||||
Virtually sets the node's position, scale and rotation to that of the given [Transform3D], then tries to move the body along the vector [code]linear_velocity[/code]. Returns [code]true[/code] if a collision would stop the body from moving along the whole path.
|
Virtually sets the node's position, scale and rotation to that of the given [Transform3D], then tries to move the body along the vector [code]distance[/code]. Returns [code]true[/code] if a collision would stop the body from moving along the whole path.
|
||||||
[code]collision[/code] is an optional object of type [KinematicCollision3D], which contains additional information about the collision when stopped, or when touching another body along the motion.
|
[code]collision[/code] is an optional object of type [KinematicCollision3D], which contains additional information about the collision when stopped, or when touching another body along the motion.
|
||||||
[code]safe_margin[/code] is the extra margin used for collision recovery (see [member CharacterBody3D.collision/safe_margin] for more details).
|
[code]safe_margin[/code] is the extra margin used for collision recovery (see [member CharacterBody3D.collision/safe_margin] for more details).
|
||||||
[code]max_collisions[/code] allows to retrieve more than one collision result.
|
[code]max_collisions[/code] allows to retrieve more than one collision result.
|
||||||
|
@ -34,8 +34,8 @@
|
|||||||
#include "scene/scene_string_names.h"
|
#include "scene/scene_string_names.h"
|
||||||
|
|
||||||
void PhysicsBody2D::_bind_methods() {
|
void PhysicsBody2D::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("move_and_collide", "linear_velocity", "test_only", "safe_margin"), &PhysicsBody2D::_move, DEFVAL(false), DEFVAL(0.08));
|
ClassDB::bind_method(D_METHOD("move_and_collide", "distance", "test_only", "safe_margin"), &PhysicsBody2D::_move, DEFVAL(false), DEFVAL(0.08));
|
||||||
ClassDB::bind_method(D_METHOD("test_move", "from", "linear_velocity", "collision", "safe_margin"), &PhysicsBody2D::test_move, DEFVAL(Variant()), DEFVAL(0.08));
|
ClassDB::bind_method(D_METHOD("test_move", "from", "distance", "collision", "safe_margin"), &PhysicsBody2D::test_move, DEFVAL(Variant()), DEFVAL(0.08));
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &PhysicsBody2D::get_collision_exceptions);
|
ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &PhysicsBody2D::get_collision_exceptions);
|
||||||
ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &PhysicsBody2D::add_collision_exception_with);
|
ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &PhysicsBody2D::add_collision_exception_with);
|
||||||
@ -54,11 +54,8 @@ PhysicsBody2D::~PhysicsBody2D() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<KinematicCollision2D> PhysicsBody2D::_move(const Vector2 &p_linear_velocity, bool p_test_only, real_t p_margin) {
|
Ref<KinematicCollision2D> PhysicsBody2D::_move(const Vector2 &p_distance, bool p_test_only, real_t p_margin) {
|
||||||
// Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky.
|
PhysicsServer2D::MotionParameters parameters(get_global_transform(), p_distance, p_margin);
|
||||||
double delta = Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time();
|
|
||||||
|
|
||||||
PhysicsServer2D::MotionParameters parameters(get_global_transform(), p_linear_velocity * delta, p_margin);
|
|
||||||
|
|
||||||
PhysicsServer2D::MotionResult result;
|
PhysicsServer2D::MotionResult result;
|
||||||
if (move_and_collide(parameters, result, p_test_only)) {
|
if (move_and_collide(parameters, result, p_test_only)) {
|
||||||
@ -129,7 +126,7 @@ bool PhysicsBody2D::move_and_collide(const PhysicsServer2D::MotionParameters &p_
|
|||||||
return colliding;
|
return colliding;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhysicsBody2D::test_move(const Transform2D &p_from, const Vector2 &p_linear_velocity, const Ref<KinematicCollision2D> &r_collision, real_t p_margin) {
|
bool PhysicsBody2D::test_move(const Transform2D &p_from, const Vector2 &p_distance, const Ref<KinematicCollision2D> &r_collision, real_t p_margin) {
|
||||||
ERR_FAIL_COND_V(!is_inside_tree(), false);
|
ERR_FAIL_COND_V(!is_inside_tree(), false);
|
||||||
|
|
||||||
PhysicsServer2D::MotionResult *r = nullptr;
|
PhysicsServer2D::MotionResult *r = nullptr;
|
||||||
@ -141,10 +138,7 @@ bool PhysicsBody2D::test_move(const Transform2D &p_from, const Vector2 &p_linear
|
|||||||
r = &temp_result;
|
r = &temp_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky.
|
PhysicsServer2D::MotionParameters parameters(p_from, p_distance, p_margin);
|
||||||
double delta = Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time();
|
|
||||||
|
|
||||||
PhysicsServer2D::MotionParameters parameters(p_from, p_linear_velocity * delta, p_margin);
|
|
||||||
|
|
||||||
bool colliding = PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), parameters, r);
|
bool colliding = PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), parameters, r);
|
||||||
|
|
||||||
|
@ -47,11 +47,11 @@ protected:
|
|||||||
|
|
||||||
Ref<KinematicCollision2D> motion_cache;
|
Ref<KinematicCollision2D> motion_cache;
|
||||||
|
|
||||||
Ref<KinematicCollision2D> _move(const Vector2 &p_linear_velocity, bool p_test_only = false, real_t p_margin = 0.08);
|
Ref<KinematicCollision2D> _move(const Vector2 &p_distance, bool p_test_only = false, real_t p_margin = 0.08);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool move_and_collide(const PhysicsServer2D::MotionParameters &p_parameters, PhysicsServer2D::MotionResult &r_result, bool p_test_only = false, bool p_cancel_sliding = true);
|
bool move_and_collide(const PhysicsServer2D::MotionParameters &p_parameters, PhysicsServer2D::MotionResult &r_result, bool p_test_only = false, bool p_cancel_sliding = true);
|
||||||
bool test_move(const Transform2D &p_from, const Vector2 &p_linear_velocity, const Ref<KinematicCollision2D> &r_collision = Ref<KinematicCollision2D>(), real_t p_margin = 0.08);
|
bool test_move(const Transform2D &p_from, const Vector2 &p_distance, const Ref<KinematicCollision2D> &r_collision = Ref<KinematicCollision2D>(), real_t p_margin = 0.08);
|
||||||
|
|
||||||
TypedArray<PhysicsBody2D> get_collision_exceptions();
|
TypedArray<PhysicsBody2D> get_collision_exceptions();
|
||||||
void add_collision_exception_with(Node *p_node); //must be physicsbody
|
void add_collision_exception_with(Node *p_node); //must be physicsbody
|
||||||
|
@ -34,8 +34,8 @@
|
|||||||
#include "scene/scene_string_names.h"
|
#include "scene/scene_string_names.h"
|
||||||
|
|
||||||
void PhysicsBody3D::_bind_methods() {
|
void PhysicsBody3D::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("move_and_collide", "linear_velocity", "test_only", "safe_margin", "max_collisions"), &PhysicsBody3D::_move, DEFVAL(false), DEFVAL(0.001), DEFVAL(1));
|
ClassDB::bind_method(D_METHOD("move_and_collide", "distance", "test_only", "safe_margin", "max_collisions"), &PhysicsBody3D::_move, DEFVAL(false), DEFVAL(0.001), DEFVAL(1));
|
||||||
ClassDB::bind_method(D_METHOD("test_move", "from", "linear_velocity", "collision", "safe_margin", "max_collisions"), &PhysicsBody3D::test_move, DEFVAL(Variant()), DEFVAL(0.001), DEFVAL(1));
|
ClassDB::bind_method(D_METHOD("test_move", "from", "distance", "collision", "safe_margin", "max_collisions"), &PhysicsBody3D::test_move, DEFVAL(Variant()), DEFVAL(0.001), DEFVAL(1));
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_axis_lock", "axis", "lock"), &PhysicsBody3D::set_axis_lock);
|
ClassDB::bind_method(D_METHOD("set_axis_lock", "axis", "lock"), &PhysicsBody3D::set_axis_lock);
|
||||||
ClassDB::bind_method(D_METHOD("get_axis_lock", "axis"), &PhysicsBody3D::get_axis_lock);
|
ClassDB::bind_method(D_METHOD("get_axis_lock", "axis"), &PhysicsBody3D::get_axis_lock);
|
||||||
@ -91,11 +91,8 @@ void PhysicsBody3D::remove_collision_exception_with(Node *p_node) {
|
|||||||
PhysicsServer3D::get_singleton()->body_remove_collision_exception(get_rid(), collision_object->get_rid());
|
PhysicsServer3D::get_singleton()->body_remove_collision_exception(get_rid(), collision_object->get_rid());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<KinematicCollision3D> PhysicsBody3D::_move(const Vector3 &p_linear_velocity, bool p_test_only, real_t p_margin, int p_max_collisions) {
|
Ref<KinematicCollision3D> PhysicsBody3D::_move(const Vector3 &p_distance, bool p_test_only, real_t p_margin, int p_max_collisions) {
|
||||||
// Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky
|
PhysicsServer3D::MotionParameters parameters(get_global_transform(), p_distance, p_margin);
|
||||||
double delta = Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time();
|
|
||||||
|
|
||||||
PhysicsServer3D::MotionParameters parameters(get_global_transform(), p_linear_velocity * delta, p_margin);
|
|
||||||
parameters.max_collisions = p_max_collisions;
|
parameters.max_collisions = p_max_collisions;
|
||||||
|
|
||||||
PhysicsServer3D::MotionResult result;
|
PhysicsServer3D::MotionResult result;
|
||||||
@ -170,7 +167,7 @@ bool PhysicsBody3D::move_and_collide(const PhysicsServer3D::MotionParameters &p_
|
|||||||
return colliding;
|
return colliding;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhysicsBody3D::test_move(const Transform3D &p_from, const Vector3 &p_linear_velocity, const Ref<KinematicCollision3D> &r_collision, real_t p_margin, int p_max_collisions) {
|
bool PhysicsBody3D::test_move(const Transform3D &p_from, const Vector3 &p_distance, const Ref<KinematicCollision3D> &r_collision, real_t p_margin, int p_max_collisions) {
|
||||||
ERR_FAIL_COND_V(!is_inside_tree(), false);
|
ERR_FAIL_COND_V(!is_inside_tree(), false);
|
||||||
|
|
||||||
PhysicsServer3D::MotionResult *r = nullptr;
|
PhysicsServer3D::MotionResult *r = nullptr;
|
||||||
@ -182,10 +179,7 @@ bool PhysicsBody3D::test_move(const Transform3D &p_from, const Vector3 &p_linear
|
|||||||
r = &temp_result;
|
r = &temp_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky
|
PhysicsServer3D::MotionParameters parameters(p_from, p_distance, p_margin);
|
||||||
double delta = Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time();
|
|
||||||
|
|
||||||
PhysicsServer3D::MotionParameters parameters(p_from, p_linear_velocity * delta, p_margin);
|
|
||||||
|
|
||||||
bool colliding = PhysicsServer3D::get_singleton()->body_test_motion(get_rid(), parameters, r);
|
bool colliding = PhysicsServer3D::get_singleton()->body_test_motion(get_rid(), parameters, r);
|
||||||
|
|
||||||
|
@ -50,11 +50,11 @@ protected:
|
|||||||
|
|
||||||
uint16_t locked_axis = 0;
|
uint16_t locked_axis = 0;
|
||||||
|
|
||||||
Ref<KinematicCollision3D> _move(const Vector3 &p_linear_velocity, bool p_test_only = false, real_t p_margin = 0.001, int p_max_collisions = 1);
|
Ref<KinematicCollision3D> _move(const Vector3 &p_distance, bool p_test_only = false, real_t p_margin = 0.001, int p_max_collisions = 1);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool move_and_collide(const PhysicsServer3D::MotionParameters &p_parameters, PhysicsServer3D::MotionResult &r_result, bool p_test_only = false, bool p_cancel_sliding = true);
|
bool move_and_collide(const PhysicsServer3D::MotionParameters &p_parameters, PhysicsServer3D::MotionResult &r_result, bool p_test_only = false, bool p_cancel_sliding = true);
|
||||||
bool test_move(const Transform3D &p_from, const Vector3 &p_linear_velocity, const Ref<KinematicCollision3D> &r_collision = Ref<KinematicCollision3D>(), real_t p_margin = 0.001, int p_max_collisions = 1);
|
bool test_move(const Transform3D &p_from, const Vector3 &p_distance, const Ref<KinematicCollision3D> &r_collision = Ref<KinematicCollision3D>(), real_t p_margin = 0.001, int p_max_collisions = 1);
|
||||||
|
|
||||||
void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock);
|
void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock);
|
||||||
bool get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const;
|
bool get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user