Browse Source

Merge pull request #58411 from cbscribe/rename_motion_velocity

Rémi Verschelde 3 years ago
parent
commit
fcf8c2006d

+ 9 - 9
doc/classes/CharacterBody2D.xml

@@ -55,7 +55,7 @@
 		<method name="get_real_velocity" qualifiers="const">
 			<return type="Vector2" />
 			<description>
-				Returns the current real velocity since the last call to [method move_and_slide]. For example, when you climb a slope, you will move diagonally even though the velocity is horizontal. This method returns the diagonal movement, as opposed to [member motion_velocity] which returns the requested velocity.
+				Returns the current real velocity since the last call to [method move_and_slide]. For example, when you climb a slope, you will move diagonally even though the velocity is horizontal. This method returns the diagonal movement, as opposed to [member velocity] which returns the requested velocity.
 			</description>
 		</method>
 		<method name="get_slide_collision">
@@ -131,8 +131,8 @@
 		<method name="move_and_slide">
 			<return type="bool" />
 			<description>
-				Moves the body based on [member motion_velocity]. If the body collides with another, it will slide along the other body (by default only on floor) rather than stop immediately. If the other body is a [CharacterBody2D] or [RigidDynamicBody2D], it will also be affected by the motion of the other body. You can use this to make moving and rotating platforms, or to make nodes push other nodes.
-				Modifies [member motion_velocity] if a slide collision occurred. To get the latest collision call [method get_last_slide_collision], for detailed information about collisions that occurred, use [method get_slide_collision].
+				Moves the body based on [member velocity]. If the body collides with another, it will slide along the other body (by default only on floor) rather than stop immediately. If the other body is a [CharacterBody2D] or [RigidDynamicBody2D], it will also be affected by the motion of the other body. You can use this to make moving and rotating platforms, or to make nodes push other nodes.
+				Modifies [member velocity] if a slide collision occurred. To get the latest collision call [method get_last_slide_collision], for detailed information about collisions that occurred, use [method get_slide_collision].
 				When the body touches a moving platform, the platform's velocity is automatically added to the body motion. If a collision occurs due to the platform's motion, it will always be first in the slide collisions.
 				The general behavior and available properties change according to the [member motion_mode].
 				Returns [code]true[/code] if the body collided, otherwise, returns [code]false[/code].
@@ -162,7 +162,7 @@
 		</member>
 		<member name="floor_stop_on_slope" type="bool" setter="set_floor_stop_on_slope_enabled" getter="is_floor_stop_on_slope_enabled" default="true">
 			If [code]true[/code], the body will not slide on slopes when calling [method move_and_slide] when the body is standing still.
-			If [code]false[/code], the body will slide on floor's slopes when [member motion_velocity] applies a downward force.
+			If [code]false[/code], the body will slide on floor's slopes when [member velocity] applies a downward force.
 		</member>
 		<member name="max_slides" type="int" setter="set_max_slides" getter="get_max_slides" default="4">
 			Maximum number of times the body can change direction before it stops when calling [method move_and_slide].
@@ -170,9 +170,6 @@
 		<member name="motion_mode" type="int" setter="set_motion_mode" getter="get_motion_mode" enum="CharacterBody2D.MotionMode" default="0">
 			Sets the motion mode which defines the behavior of [method move_and_slide]. See [enum MotionMode] constants for available modes.
 		</member>
-		<member name="motion_velocity" type="Vector2" setter="set_motion_velocity" getter="get_motion_velocity" default="Vector2(0, 0)">
-			Current velocity vector in pixels per second, used and modified during calls to [method move_and_slide].
-		</member>
 		<member name="moving_platform_apply_velocity_on_leave" type="int" setter="set_moving_platform_apply_velocity_on_leave" getter="get_moving_platform_apply_velocity_on_leave" enum="CharacterBody2D.MovingPlatformApplyVelocityOnLeave" default="0">
 			Sets the behavior to apply when you leave a moving platform. By default, to be physically accurate, when you leave the last platform velocity is applied. See [enum MovingPlatformApplyVelocityOnLeave] constants for available behavior.
 		</member>
@@ -188,6 +185,9 @@
 		<member name="up_direction" type="Vector2" setter="set_up_direction" getter="get_up_direction" default="Vector2(0, -1)">
 			Direction vector used to determine what is a wall and what is a floor (or a ceiling), rather than a wall, when calling [method move_and_slide]. Defaults to [code]Vector2.UP[/code]. If set to [code]Vector2(0, 0)[/code], everything is considered a wall. This is useful for topdown games.
 		</member>
+		<member name="velocity" type="Vector2" setter="set_velocity" getter="get_velocity" default="Vector2(0, 0)">
+			Current velocity vector in pixels per second, used and modified during calls to [method move_and_slide].
+		</member>
 		<member name="wall_min_slide_angle" type="float" setter="set_wall_min_slide_angle" getter="get_wall_min_slide_angle" default="0.261799">
 			Minimum angle (in radians) where the body is allowed to slide when it encounters a slope. The default value equals 15 degrees. This property only affects movement when [member motion_mode] is [constant MOTION_MODE_FLOATING].
 		</member>
@@ -200,10 +200,10 @@
 			Apply when there is no notion of floor or ceiling. All collisions will be reported as [code]on_wall[/code]. In this mode, when you slide, the speed will always be constant. This mode is suitable for top-down games.
 		</constant>
 		<constant name="PLATFORM_VEL_ON_LEAVE_ALWAYS" value="0" enum="MovingPlatformApplyVelocityOnLeave">
-			Add the last platform velocity to the [member motion_velocity] when you leave a moving platform.
+			Add the last platform velocity to the [member velocity] when you leave a moving platform.
 		</constant>
 		<constant name="PLATFORM_VEL_ON_LEAVE_UPWARD_ONLY" value="1" enum="MovingPlatformApplyVelocityOnLeave">
-			Add the last platform velocity to the [member motion_velocity] when you leave a moving platform, but any downward motion is ignored. It's useful to keep full jump height even when the platform is moving down.
+			Add the last platform velocity to the [member velocity] when you leave a moving platform, but any downward motion is ignored. It's useful to keep full jump height even when the platform is moving down.
 		</constant>
 		<constant name="PLATFORM_VEL_ON_LEAVE_NEVER" value="2" enum="MovingPlatformApplyVelocityOnLeave">
 			Do nothing when leaving a platform.

+ 9 - 9
doc/classes/CharacterBody3D.xml

@@ -56,7 +56,7 @@
 		<method name="get_real_velocity" qualifiers="const">
 			<return type="Vector3" />
 			<description>
-				Returns the current real velocity since the last call to [method move_and_slide]. For example, when you climb a slope, you will move diagonally even though the velocity is horizontal. This method returns the diagonal movement, as opposed to [member motion_velocity] which returns the requested velocity.
+				Returns the current real velocity since the last call to [method move_and_slide]. For example, when you climb a slope, you will move diagonally even though the velocity is horizontal. This method returns the diagonal movement, as opposed to [member velocity] which returns the requested velocity.
 			</description>
 		</method>
 		<method name="get_slide_collision">
@@ -117,8 +117,8 @@
 		<method name="move_and_slide">
 			<return type="bool" />
 			<description>
-				Moves the body based on [member motion_velocity]. If the body collides with another, it will slide along the other body rather than stop immediately. If the other body is a [CharacterBody3D] or [RigidDynamicBody3D], it will also be affected by the motion of the other body. You can use this to make moving and rotating platforms, or to make nodes push other nodes.
-				Modifies [member motion_velocity] if a slide collision occurred. To get the latest collision call [method get_last_slide_collision], for more detailed information about collisions that occurred, use [method get_slide_collision].
+				Moves the body based on [member velocity]. If the body collides with another, it will slide along the other body rather than stop immediately. If the other body is a [CharacterBody3D] or [RigidDynamicBody3D], it will also be affected by the motion of the other body. You can use this to make moving and rotating platforms, or to make nodes push other nodes.
+				Modifies [member velocity] if a slide collision occurred. To get the latest collision call [method get_last_slide_collision], for more detailed information about collisions that occurred, use [method get_slide_collision].
 				When the body touches a moving platform, the platform's velocity is automatically added to the body motion. If a collision occurs due to the platform's motion, it will always be first in the slide collisions.
 				Returns [code]true[/code] if the body collided, otherwise, returns [code]false[/code].
 			</description>
@@ -147,7 +147,7 @@
 		</member>
 		<member name="floor_stop_on_slope" type="bool" setter="set_floor_stop_on_slope_enabled" getter="is_floor_stop_on_slope_enabled" default="true">
 			If [code]true[/code], the body will not slide on slopes when calling [method move_and_slide] when the body is standing still.
-			If [code]false[/code], the body will slide on floor's slopes when [member motion_velocity] applies a downward force.
+			If [code]false[/code], the body will slide on floor's slopes when [member velocity] applies a downward force.
 		</member>
 		<member name="max_slides" type="int" setter="set_max_slides" getter="get_max_slides" default="6">
 			Maximum number of times the body can change direction before it stops when calling [method move_and_slide].
@@ -155,9 +155,6 @@
 		<member name="motion_mode" type="int" setter="set_motion_mode" getter="get_motion_mode" enum="CharacterBody3D.MotionMode" default="0">
 			Sets the motion mode which defines the behavior of [method move_and_slide]. See [enum MotionMode] constants for available modes.
 		</member>
-		<member name="motion_velocity" type="Vector3" setter="set_motion_velocity" getter="get_motion_velocity" default="Vector3(0, 0, 0)">
-			Current velocity vector (typically meters per second), used and modified during calls to [method move_and_slide].
-		</member>
 		<member name="moving_platform_apply_velocity_on_leave" type="int" setter="set_moving_platform_apply_velocity_on_leave" getter="get_moving_platform_apply_velocity_on_leave" enum="CharacterBody3D.MovingPlatformApplyVelocityOnLeave" default="0">
 			Sets the behavior to apply when you leave a moving platform. By default, to be physically accurate, when you leave the last platform velocity is applied. See [enum MovingPlatformApplyVelocityOnLeave] constants for available behavior.
 		</member>
@@ -173,6 +170,9 @@
 		<member name="up_direction" type="Vector3" setter="set_up_direction" getter="get_up_direction" default="Vector3(0, 1, 0)">
 			Direction vector used to determine what is a wall and what is a floor (or a ceiling), rather than a wall, when calling [method move_and_slide]. Defaults to [code]Vector3.UP[/code]. If set to [code]Vector3(0, 0, 0)[/code], everything is considered a wall. This is useful for topdown games.
 		</member>
+		<member name="velocity" type="Vector3" setter="set_velocity" getter="get_velocity" default="Vector3(0, 0, 0)">
+			Current velocity vector (typically meters per second), used and modified during calls to [method move_and_slide].
+		</member>
 		<member name="wall_min_slide_angle" type="float" setter="set_wall_min_slide_angle" getter="get_wall_min_slide_angle" default="0.261799">
 			Minimum angle (in radians) where the body is allowed to slide when it encounters a slope. The default value equals 15 degrees. When [member motion_mode] is [constant MOTION_MODE_GROUNDED], it only affects movement if [member floor_block_on_wall] is [code]true[/code].
 		</member>
@@ -185,10 +185,10 @@
 			Apply when there is no notion of floor or ceiling. All collisions will be reported as [code]on_wall[/code]. In this mode, when you slide, the speed will always be constant. This mode is suitable for games without ground like space games.
 		</constant>
 		<constant name="PLATFORM_VEL_ON_LEAVE_ALWAYS" value="0" enum="MovingPlatformApplyVelocityOnLeave">
-			Add the last platform velocity to the [member motion_velocity] when you leave a moving platform.
+			Add the last platform velocity to the [member velocity] when you leave a moving platform.
 		</constant>
 		<constant name="PLATFORM_VEL_ON_LEAVE_UPWARD_ONLY" value="1" enum="MovingPlatformApplyVelocityOnLeave">
-			Add the last platform velocity to the [member motion_velocity] when you leave a moving platform, but any downward motion is ignored. It's useful to keep full jump height even when the platform is moving down.
+			Add the last platform velocity to the [member velocity] when you leave a moving platform, but any downward motion is ignored. It's useful to keep full jump height even when the platform is moving down.
 		</constant>
 		<constant name="PLATFORM_VEL_ON_LEAVE_NEVER" value="2" enum="MovingPlatformApplyVelocityOnLeave">
 			Do nothing when leaving a platform.

+ 4 - 4
modules/gdscript/editor_templates/CharacterBody2D/basic_movement.gd

@@ -12,18 +12,18 @@ var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
 func _physics_process(delta: float) -> void:
 	# Add the gravity.
 	if not is_on_floor():
-		motion_velocity.y += gravity * delta
+		velocity.y += gravity * delta
 
 	# Handle Jump.
 	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
-		motion_velocity.y = JUMP_VELOCITY
+		velocity.y = JUMP_VELOCITY
 
 	# Get the input direction and handle the movement/deceleration.
 	# As good practice, you should replace UI actions with custom gameplay actions.
 	var direction := Input.get_axis("ui_left", "ui_right")
 	if direction:
-		motion_velocity.x = direction * SPEED
+		velocity.x = direction * SPEED
 	else:
-		motion_velocity.x = move_toward(motion_velocity.x, 0, SPEED)
+		velocity.x = move_toward(velocity.x, 0, SPEED)
 
 	move_and_slide()

+ 6 - 6
modules/gdscript/editor_templates/CharacterBody3D/basic_movement.gd

@@ -12,21 +12,21 @@ var gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity")
 func _physics_process(delta: float) -> void:
 	# Add the gravity.
 	if not is_on_floor():
-		motion_velocity.y -= gravity * delta
+		velocity.y -= gravity * delta
 
 	# Handle Jump.
 	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
-		motion_velocity.y = JUMP_VELOCITY
+		velocity.y = JUMP_VELOCITY
 
 	# Get the input direction and handle the movement/deceleration.
 	# As good practice, you should replace UI actions with custom gameplay actions.
 	var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
 	var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
 	if direction:
-		motion_velocity.x = direction.x * SPEED
-		motion_velocity.z = direction.z * SPEED
+		velocity.x = direction.x * SPEED
+		velocity.z = direction.z * SPEED
 	else:
-		motion_velocity.x = move_toward(motion_velocity.x, 0, SPEED)
-		motion_velocity.z = move_toward(motion_velocity.z, 0, SPEED)
+		velocity.x = move_toward(velocity.x, 0, SPEED)
+		velocity.z = move_toward(velocity.z, 0, SPEED)
 
 	move_and_slide()

+ 6 - 6
modules/mono/editor_templates/CharacterBody2D/basic_movement.cs

@@ -13,29 +13,29 @@ public partial class _CLASS_ : _BASE_
 
     public override void _PhysicsProcess(float delta)
     {
-        Vector2 motionVelocity = MotionVelocity;
+        Vector2 velocity = Velocity;
 
         // Add the gravity.
         if (!IsOnFloor())
-            motionVelocity.y += gravity * delta;
+            velocity.y += gravity * delta;
 
         // Handle Jump.
         if (Input.IsActionJustPressed("ui_accept") && IsOnFloor())
-            motionVelocity.y = JumpVelocity;
+            velocity.y = JumpVelocity;
 
         // Get the input direction and handle the movement/deceleration.
         // As good practice, you should replace UI actions with custom gameplay actions.
         Vector2 direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down");
         if (direction != Vector2.Zero)
         {
-            motionVelocity.x = direction.x * Speed;
+            velocity.x = direction.x * Speed;
         }
         else
         {
-            motionVelocity.x = Mathf.MoveToward(MotionVelocity.x, 0, Speed);
+            velocity.x = Mathf.MoveToward(Velocity.x, 0, Speed);
         }
 
-        MotionVelocity = motionVelocity;
+        Velocity = velocity;
         MoveAndSlide();
     }
 }

+ 8 - 8
modules/mono/editor_templates/CharacterBody3D/basic_movement.cs

@@ -13,15 +13,15 @@ public partial class _CLASS_ : _BASE_
 
     public override void _PhysicsProcess(float delta)
     {
-        Vector3 motionVelocity = MotionVelocity;
+        Vector3 velocity = Velocity;
 
         // Add the gravity.
         if (!IsOnFloor())
-            motionVelocity.y -= gravity * delta;
+            velocity.y -= gravity * delta;
 
         // Handle Jump.
         if (Input.IsActionJustPressed("ui_accept") && IsOnFloor())
-             motionVelocity.y = JumpVelocity;
+             velocity.y = JumpVelocity;
 
         // Get the input direction and handle the movement/deceleration.
         // As good practice, you should replace UI actions with custom gameplay actions.
@@ -29,16 +29,16 @@ public partial class _CLASS_ : _BASE_
         Vector3 direction = Transform.basis.Xform(new Vector3(inputDir.x, 0, inputDir.y)).Normalized();
         if (direction != Vector3.Zero)
         {
-            motionVelocity.x = direction.x * Speed;
-            motionVelocity.z = direction.z * Speed;
+            velocity.x = direction.x * Speed;
+            velocity.z = direction.z * Speed;
         }
         else
         {
-            motionVelocity.x = Mathf.MoveToward(MotionVelocity.x, 0, Speed);
-            motionVelocity.z = Mathf.MoveToward(MotionVelocity.z, 0, Speed);
+            velocity.x = Mathf.MoveToward(Velocity.x, 0, Speed);
+            velocity.z = Mathf.MoveToward(Velocity.z, 0, Speed);
         }
 
-        MotionVelocity = motionVelocity;
+        Velocity = velocity;
         MoveAndSlide();
     }
 }

+ 28 - 28
scene/2d/physics_body_2d.cpp

@@ -1168,7 +1168,7 @@ bool CharacterBody2D::move_and_slide() {
 			if (moving_platform_apply_velocity_on_leave == PLATFORM_VEL_ON_LEAVE_UPWARD_ONLY && current_platform_velocity.dot(up_direction) < 0) {
 				current_platform_velocity = current_platform_velocity.slide(up_direction);
 			}
-			motion_velocity += current_platform_velocity;
+			velocity += current_platform_velocity;
 		}
 	}
 
@@ -1176,7 +1176,7 @@ bool CharacterBody2D::move_and_slide() {
 }
 
 void CharacterBody2D::_move_and_slide_grounded(double p_delta, bool p_was_on_floor) {
-	Vector2 motion = motion_velocity * p_delta;
+	Vector2 motion = velocity * p_delta;
 	Vector2 motion_slide_up = motion.slide(up_direction);
 
 	Vector2 prev_floor_normal = floor_normal;
@@ -1194,7 +1194,7 @@ void CharacterBody2D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 	// If the platform's ceiling push down the body.
 	bool apply_ceiling_velocity = false;
 	bool first_slide = true;
-	bool vel_dir_facing_up = motion_velocity.dot(up_direction) > 0;
+	bool vel_dir_facing_up = velocity.dot(up_direction) > 0;
 	Vector2 last_travel;
 
 	for (int iteration = 0; iteration < max_slides; ++iteration) {
@@ -1211,26 +1211,26 @@ void CharacterBody2D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 			motion_results.push_back(result);
 			_set_collision_direction(result);
 
-			// If we hit a ceiling platform, we set the vertical motion_velocity to at least the platform one.
+			// If we hit a ceiling platform, we set the vertical velocity to at least the platform one.
 			if (on_ceiling && result.collider_velocity != Vector2() && result.collider_velocity.dot(up_direction) < 0) {
 				// If ceiling sliding is on, only apply when the ceiling is flat or when the motion is upward.
 				if (!slide_on_ceiling || motion.dot(up_direction) < 0 || (result.collision_normal + up_direction).length() < 0.01) {
 					apply_ceiling_velocity = true;
 					Vector2 ceiling_vertical_velocity = up_direction * up_direction.dot(result.collider_velocity);
-					Vector2 motion_vertical_velocity = up_direction * up_direction.dot(motion_velocity);
+					Vector2 motion_vertical_velocity = up_direction * up_direction.dot(velocity);
 					if (motion_vertical_velocity.dot(up_direction) > 0 || ceiling_vertical_velocity.length_squared() > motion_vertical_velocity.length_squared()) {
-						motion_velocity = ceiling_vertical_velocity + motion_velocity.slide(up_direction);
+						velocity = ceiling_vertical_velocity + velocity.slide(up_direction);
 					}
 				}
 			}
 
-			if (on_floor && floor_stop_on_slope && (motion_velocity.normalized() + up_direction).length() < 0.01) {
+			if (on_floor && floor_stop_on_slope && (velocity.normalized() + up_direction).length() < 0.01) {
 				Transform2D gt = get_global_transform();
 				if (result.travel.length() <= margin + CMP_EPSILON) {
 					gt.elements[2] -= result.travel;
 				}
 				set_global_transform(gt);
-				motion_velocity = Vector2();
+				velocity = Vector2();
 				last_motion = Vector2();
 				motion = Vector2();
 				break;
@@ -1254,7 +1254,7 @@ void CharacterBody2D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 					}
 					// Determines if you are on the ground.
 					_snap_on_floor(true, false);
-					motion_velocity = Vector2();
+					velocity = Vector2();
 					last_motion = Vector2();
 					motion = Vector2();
 					break;
@@ -1276,7 +1276,7 @@ void CharacterBody2D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 			// Regular sliding, the last part of the test handle the case when you don't want to slide on the ceiling.
 			else if ((sliding_enabled || !on_floor) && (!on_ceiling || slide_on_ceiling || !vel_dir_facing_up) && !apply_ceiling_velocity) {
 				Vector2 slide_motion = result.remainder.slide(result.collision_normal);
-				if (slide_motion.dot(motion_velocity) > 0.0) {
+				if (slide_motion.dot(velocity) > 0.0) {
 					motion = slide_motion;
 				} else {
 					motion = Vector2();
@@ -1284,10 +1284,10 @@ void CharacterBody2D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 				if (slide_on_ceiling && on_ceiling) {
 					// Apply slide only in the direction of the input motion, otherwise just stop to avoid jittering when moving against a wall.
 					if (vel_dir_facing_up) {
-						motion_velocity = motion_velocity.slide(result.collision_normal);
+						velocity = velocity.slide(result.collision_normal);
 					} else {
 						// Avoid acceleration in slope when falling.
-						motion_velocity = up_direction * up_direction.dot(motion_velocity);
+						velocity = up_direction * up_direction.dot(velocity);
 					}
 				}
 			}
@@ -1295,7 +1295,7 @@ void CharacterBody2D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 			else {
 				motion = result.remainder;
 				if (on_ceiling && !slide_on_ceiling && vel_dir_facing_up) {
-					motion_velocity = motion_velocity.slide(up_direction);
+					velocity = velocity.slide(up_direction);
 					motion = motion.slide(up_direction);
 				}
 			}
@@ -1329,23 +1329,23 @@ void CharacterBody2D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 
 	// Scales the horizontal velocity according to the wall slope.
 	if (is_on_wall_only() && motion_slide_up.dot(motion_results.get(0).collision_normal) < 0) {
-		Vector2 slide_motion = motion_velocity.slide(motion_results.get(0).collision_normal);
+		Vector2 slide_motion = velocity.slide(motion_results.get(0).collision_normal);
 		if (motion_slide_up.dot(slide_motion) < 0) {
-			motion_velocity = up_direction * up_direction.dot(motion_velocity);
+			velocity = up_direction * up_direction.dot(velocity);
 		} else {
-			// Keeps the vertical motion from motion_velocity and add the horizontal motion of the projection.
-			motion_velocity = up_direction * up_direction.dot(motion_velocity) + slide_motion.slide(up_direction);
+			// Keeps the vertical motion from velocity and add the horizontal motion of the projection.
+			velocity = up_direction * up_direction.dot(velocity) + slide_motion.slide(up_direction);
 		}
 	}
 
 	// Reset the gravity accumulation when touching the ground.
 	if (on_floor && !vel_dir_facing_up) {
-		motion_velocity = motion_velocity.slide(up_direction);
+		velocity = velocity.slide(up_direction);
 	}
 }
 
 void CharacterBody2D::_move_and_slide_floating(double p_delta) {
-	Vector2 motion = motion_velocity * p_delta;
+	Vector2 motion = velocity * p_delta;
 
 	platform_rid = RID();
 	platform_object_id = ObjectID();
@@ -1370,7 +1370,7 @@ void CharacterBody2D::_move_and_slide_floating(double p_delta) {
 				break;
 			}
 
-			if (wall_min_slide_angle != 0 && result.get_angle(-motion_velocity.normalized()) < wall_min_slide_angle + FLOOR_ANGLE_THRESHOLD) {
+			if (wall_min_slide_angle != 0 && result.get_angle(-velocity.normalized()) < wall_min_slide_angle + FLOOR_ANGLE_THRESHOLD) {
 				motion = Vector2();
 			} else if (first_slide) {
 				Vector2 motion_slide_norm = result.remainder.slide(result.collision_normal).normalized();
@@ -1379,7 +1379,7 @@ void CharacterBody2D::_move_and_slide_floating(double p_delta) {
 				motion = result.remainder.slide(result.collision_normal);
 			}
 
-			if (motion.dot(motion_velocity) <= 0.0) {
+			if (motion.dot(velocity) <= 0.0) {
 				motion = Vector2();
 			}
 		}
@@ -1471,12 +1471,12 @@ void CharacterBody2D::_set_platform_data(const PhysicsServer2D::MotionResult &p_
 	platform_layer = PhysicsServer2D::get_singleton()->body_get_collision_layer(platform_rid);
 }
 
-const Vector2 &CharacterBody2D::get_motion_velocity() const {
-	return motion_velocity;
+const Vector2 &CharacterBody2D::get_velocity() const {
+	return velocity;
 }
 
-void CharacterBody2D::set_motion_velocity(const Vector2 &p_velocity) {
-	motion_velocity = p_velocity;
+void CharacterBody2D::set_velocity(const Vector2 &p_velocity) {
+	velocity = p_velocity;
 }
 
 bool CharacterBody2D::is_on_floor() const {
@@ -1697,8 +1697,8 @@ void CharacterBody2D::_notification(int p_what) {
 void CharacterBody2D::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("move_and_slide"), &CharacterBody2D::move_and_slide);
 
-	ClassDB::bind_method(D_METHOD("set_motion_velocity", "motion_velocity"), &CharacterBody2D::set_motion_velocity);
-	ClassDB::bind_method(D_METHOD("get_motion_velocity"), &CharacterBody2D::get_motion_velocity);
+	ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &CharacterBody2D::set_velocity);
+	ClassDB::bind_method(D_METHOD("get_velocity"), &CharacterBody2D::get_velocity);
 
 	ClassDB::bind_method(D_METHOD("set_safe_margin", "pixels"), &CharacterBody2D::set_safe_margin);
 	ClassDB::bind_method(D_METHOD("get_safe_margin"), &CharacterBody2D::get_safe_margin);
@@ -1750,7 +1750,7 @@ void CharacterBody2D::_bind_methods() {
 
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "motion_mode", PROPERTY_HINT_ENUM, "Grounded,Floating", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_motion_mode", "get_motion_mode");
 	ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "up_direction"), "set_up_direction", "get_up_direction");
-	ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "motion_velocity", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_motion_velocity", "get_motion_velocity");
+	ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "velocity", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_velocity", "get_velocity");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "slide_on_ceiling"), "set_slide_on_ceiling_enabled", "is_slide_on_ceiling_enabled");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "max_slides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_max_slides", "get_max_slides");
 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "wall_min_slide_angle", PROPERTY_HINT_RANGE, "0,180,0.1,radians", PROPERTY_USAGE_DEFAULT), "set_wall_min_slide_angle", "get_wall_min_slide_angle");

+ 3 - 3
scene/2d/physics_body_2d.h

@@ -337,8 +337,8 @@ public:
 	};
 	bool move_and_slide();
 
-	const Vector2 &get_motion_velocity() const;
-	void set_motion_velocity(const Vector2 &p_velocity);
+	const Vector2 &get_velocity() const;
+	void set_velocity(const Vector2 &p_velocity);
 
 	bool is_on_floor() const;
 	bool is_on_floor_only() const;
@@ -378,7 +378,7 @@ private:
 	Vector2 up_direction = Vector2(0.0, -1.0);
 	uint32_t moving_platform_floor_layers = UINT32_MAX;
 	uint32_t moving_platform_wall_layers = 0;
-	Vector2 motion_velocity;
+	Vector2 velocity;
 
 	Vector2 floor_normal;
 	Vector2 platform_velocity;

+ 30 - 30
scene/3d/physics_body_3d.cpp

@@ -1169,7 +1169,7 @@ bool CharacterBody3D::move_and_slide() {
 
 	for (int i = 0; i < 3; i++) {
 		if (locked_axis & (1 << i)) {
-			motion_velocity[i] = 0.0;
+			velocity[i] = 0.0;
 		}
 	}
 
@@ -1239,7 +1239,7 @@ bool CharacterBody3D::move_and_slide() {
 			if (moving_platform_apply_velocity_on_leave == PLATFORM_VEL_ON_LEAVE_UPWARD_ONLY && current_platform_velocity.dot(up_direction) < 0) {
 				current_platform_velocity = current_platform_velocity.slide(up_direction);
 			}
-			motion_velocity += current_platform_velocity;
+			velocity += current_platform_velocity;
 		}
 	}
 
@@ -1247,7 +1247,7 @@ bool CharacterBody3D::move_and_slide() {
 }
 
 void CharacterBody3D::_move_and_slide_grounded(double p_delta, bool p_was_on_floor) {
-	Vector3 motion = motion_velocity * p_delta;
+	Vector3 motion = velocity * p_delta;
 	Vector3 motion_slide_up = motion.slide(up_direction);
 	Vector3 prev_floor_normal = floor_normal;
 
@@ -1267,7 +1267,7 @@ void CharacterBody3D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 	// If the platform's ceiling push down the body.
 	bool apply_ceiling_velocity = false;
 	bool first_slide = true;
-	bool vel_dir_facing_up = motion_velocity.dot(up_direction) > 0;
+	bool vel_dir_facing_up = velocity.dot(up_direction) > 0;
 	Vector3 total_travel;
 
 	for (int iteration = 0; iteration < max_slides; ++iteration) {
@@ -1287,26 +1287,26 @@ void CharacterBody3D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 			CollisionState result_state;
 			_set_collision_direction(result, result_state);
 
-			// If we hit a ceiling platform, we set the vertical motion_velocity to at least the platform one.
+			// If we hit a ceiling platform, we set the vertical velocity to at least the platform one.
 			if (collision_state.ceiling && platform_ceiling_velocity != Vector3() && platform_ceiling_velocity.dot(up_direction) < 0) {
 				// If ceiling sliding is on, only apply when the ceiling is flat or when the motion is upward.
 				if (!slide_on_ceiling || motion.dot(up_direction) < 0 || (ceiling_normal + up_direction).length() < 0.01) {
 					apply_ceiling_velocity = true;
 					Vector3 ceiling_vertical_velocity = up_direction * up_direction.dot(platform_ceiling_velocity);
-					Vector3 motion_vertical_velocity = up_direction * up_direction.dot(motion_velocity);
+					Vector3 motion_vertical_velocity = up_direction * up_direction.dot(velocity);
 					if (motion_vertical_velocity.dot(up_direction) > 0 || ceiling_vertical_velocity.length_squared() > motion_vertical_velocity.length_squared()) {
-						motion_velocity = ceiling_vertical_velocity + motion_velocity.slide(up_direction);
+						velocity = ceiling_vertical_velocity + velocity.slide(up_direction);
 					}
 				}
 			}
 
-			if (collision_state.floor && floor_stop_on_slope && (motion_velocity.normalized() + up_direction).length() < 0.01) {
+			if (collision_state.floor && floor_stop_on_slope && (velocity.normalized() + up_direction).length() < 0.01) {
 				Transform3D gt = get_global_transform();
 				if (result.travel.length() <= margin + CMP_EPSILON) {
 					gt.origin -= result.travel;
 				}
 				set_global_transform(gt);
-				motion_velocity = Vector3();
+				velocity = Vector3();
 				motion = Vector3();
 				last_motion = Vector3();
 				break;
@@ -1367,11 +1367,11 @@ void CharacterBody3D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 
 						// Scales the horizontal velocity according to the wall slope.
 						if (vel_dir_facing_up) {
-							Vector3 slide_motion = motion_velocity.slide(result.collisions[0].normal);
-							// Keeps the vertical motion from motion_velocity and add the horizontal motion of the projection.
-							motion_velocity = up_direction * up_direction.dot(motion_velocity) + slide_motion.slide(up_direction);
+							Vector3 slide_motion = velocity.slide(result.collisions[0].normal);
+							// Keeps the vertical motion from velocity and add the horizontal motion of the projection.
+							velocity = up_direction * up_direction.dot(velocity) + slide_motion.slide(up_direction);
 						} else {
-							motion_velocity = motion_velocity.slide(forward);
+							velocity = velocity.slide(forward);
 						}
 
 						// Allow only lateral motion along previous floor when already on floor.
@@ -1401,7 +1401,7 @@ void CharacterBody3D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 
 						if (stop_all_motion) {
 							motion = Vector3();
-							motion_velocity = Vector3();
+							velocity = Vector3();
 						}
 					}
 				}
@@ -1412,7 +1412,7 @@ void CharacterBody3D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 					real_t motion_angle = Math::abs(Math::acos(-horizontal_normal.dot(motion_slide_up.normalized())));
 					if (motion_angle < wall_min_slide_angle) {
 						motion = up_direction * motion.dot(up_direction);
-						motion_velocity = up_direction * motion_velocity.dot(up_direction);
+						velocity = up_direction * velocity.dot(up_direction);
 
 						apply_default_sliding = false;
 					}
@@ -1437,7 +1437,7 @@ void CharacterBody3D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 						slide_motion *= motion_length;
 					}
 
-					if (slide_motion.dot(motion_velocity) > 0.0) {
+					if (slide_motion.dot(velocity) > 0.0) {
 						motion = slide_motion;
 					} else {
 						motion = Vector3();
@@ -1446,10 +1446,10 @@ void CharacterBody3D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 					if (slide_on_ceiling && result_state.ceiling) {
 						// Apply slide only in the direction of the input motion, otherwise just stop to avoid jittering when moving against a wall.
 						if (vel_dir_facing_up) {
-							motion_velocity = motion_velocity.slide(collision.normal);
+							velocity = velocity.slide(collision.normal);
 						} else {
 							// Avoid acceleration in slope when falling.
-							motion_velocity = up_direction * up_direction.dot(motion_velocity);
+							velocity = up_direction * up_direction.dot(velocity);
 						}
 					}
 				}
@@ -1457,7 +1457,7 @@ void CharacterBody3D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 				else {
 					motion = result.remainder;
 					if (result_state.ceiling && !slide_on_ceiling && vel_dir_facing_up) {
-						motion_velocity = motion_velocity.slide(up_direction);
+						velocity = velocity.slide(up_direction);
 						motion = motion.slide(up_direction);
 					}
 				}
@@ -1502,12 +1502,12 @@ void CharacterBody3D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
 
 	// Reset the gravity accumulation when touching the ground.
 	if (collision_state.floor && !vel_dir_facing_up) {
-		motion_velocity = motion_velocity.slide(up_direction);
+		velocity = velocity.slide(up_direction);
 	}
 }
 
 void CharacterBody3D::_move_and_slide_floating(double p_delta) {
-	Vector3 motion = motion_velocity * p_delta;
+	Vector3 motion = velocity * p_delta;
 
 	platform_rid = RID();
 	platform_object_id = ObjectID();
@@ -1534,7 +1534,7 @@ void CharacterBody3D::_move_and_slide_floating(double p_delta) {
 				break;
 			}
 
-			if (wall_min_slide_angle != 0 && Math::acos(wall_normal.dot(-motion_velocity.normalized())) < wall_min_slide_angle + FLOOR_ANGLE_THRESHOLD) {
+			if (wall_min_slide_angle != 0 && Math::acos(wall_normal.dot(-velocity.normalized())) < wall_min_slide_angle + FLOOR_ANGLE_THRESHOLD) {
 				motion = Vector3();
 				if (result.travel.length() < margin + CMP_EPSILON) {
 					Transform3D gt = get_global_transform();
@@ -1548,7 +1548,7 @@ void CharacterBody3D::_move_and_slide_floating(double p_delta) {
 				motion = result.remainder.slide(wall_normal);
 			}
 
-			if (motion.dot(motion_velocity) <= 0.0) {
+			if (motion.dot(velocity) <= 0.0) {
 				motion = Vector3();
 			}
 		}
@@ -1723,12 +1723,12 @@ real_t CharacterBody3D::get_safe_margin() const {
 	return margin;
 }
 
-const Vector3 &CharacterBody3D::get_motion_velocity() const {
-	return motion_velocity;
+const Vector3 &CharacterBody3D::get_velocity() const {
+	return velocity;
 }
 
-void CharacterBody3D::set_motion_velocity(const Vector3 &p_velocity) {
-	motion_velocity = p_velocity;
+void CharacterBody3D::set_velocity(const Vector3 &p_velocity) {
+	velocity = p_velocity;
 }
 
 bool CharacterBody3D::is_on_floor() const {
@@ -1943,8 +1943,8 @@ void CharacterBody3D::_notification(int p_what) {
 void CharacterBody3D::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("move_and_slide"), &CharacterBody3D::move_and_slide);
 
-	ClassDB::bind_method(D_METHOD("set_motion_velocity", "motion_velocity"), &CharacterBody3D::set_motion_velocity);
-	ClassDB::bind_method(D_METHOD("get_motion_velocity"), &CharacterBody3D::get_motion_velocity);
+	ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &CharacterBody3D::set_velocity);
+	ClassDB::bind_method(D_METHOD("get_velocity"), &CharacterBody3D::get_velocity);
 
 	ClassDB::bind_method(D_METHOD("set_safe_margin", "pixels"), &CharacterBody3D::set_safe_margin);
 	ClassDB::bind_method(D_METHOD("get_safe_margin"), &CharacterBody3D::get_safe_margin);
@@ -1997,7 +1997,7 @@ void CharacterBody3D::_bind_methods() {
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "motion_mode", PROPERTY_HINT_ENUM, "Grounded,Floating", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_motion_mode", "get_motion_mode");
 	ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "up_direction"), "set_up_direction", "get_up_direction");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "slide_on_ceiling"), "set_slide_on_ceiling_enabled", "is_slide_on_ceiling_enabled");
-	ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "motion_velocity", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_motion_velocity", "get_motion_velocity");
+	ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "velocity", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_velocity", "get_velocity");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "max_slides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_max_slides", "get_max_slides");
 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "wall_min_slide_angle", PROPERTY_HINT_RANGE, "0,180,0.1,radians", PROPERTY_USAGE_DEFAULT), "set_wall_min_slide_angle", "get_wall_min_slide_angle");
 	ADD_GROUP("Floor", "floor_");

+ 3 - 3
scene/3d/physics_body_3d.h

@@ -354,8 +354,8 @@ public:
 	};
 	bool move_and_slide();
 
-	const Vector3 &get_motion_velocity() const;
-	void set_motion_velocity(const Vector3 &p_velocity);
+	const Vector3 &get_velocity() const;
+	void set_velocity(const Vector3 &p_velocity);
 
 	bool is_on_floor() const;
 	bool is_on_floor_only() const;
@@ -416,7 +416,7 @@ private:
 	real_t floor_max_angle = Math::deg2rad((real_t)45.0);
 	real_t wall_min_slide_angle = Math::deg2rad((real_t)15.0);
 	Vector3 up_direction = Vector3(0.0, 1.0, 0.0);
-	Vector3 motion_velocity;
+	Vector3 velocity;
 	Vector3 floor_normal;
 	Vector3 wall_normal;
 	Vector3 ceiling_normal;