Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tutorials/math/vectors_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ degrees to either side:
.. code-tab:: gdscript GDScript

# Calculate vector from `a` to `b`.
var dvec = (point_b - point_a).normalized()
var dvec = point_a.direction_to(point_b)
# Rotate 90 degrees.
var normal = Vector2(dvec.y, -dvec.x)
# Alternatively (depending the desired side of the normal):
Expand All @@ -187,7 +187,7 @@ degrees to either side:
.. code-tab:: csharp

// Calculate vector from `a` to `b`.
var dvec = (pointB - pointA).Normalized();
var dvec = pointA.DirectionTo(pointB);
// Rotate 90 degrees.
var normal = new Vector2(dvec.y, -dvec.x);
// Alternatively (depending the desired side of the normal):
Expand Down
12 changes: 2 additions & 10 deletions tutorials/navigation/navigation_introduction_2d.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,7 @@ NavigationServer2D and a NavigationAgent2D for path movement.
var current_agent_position: Vector2 = global_position
var next_path_position: Vector2 = navigation_agent.get_next_path_position()

var new_velocity: Vector2 = next_path_position - current_agent_position
new_velocity = new_velocity.normalized()
new_velocity = new_velocity * movement_speed

velocity = new_velocity
velocity = current_agent_position.direction_to(next_path_position) * movement_speed
move_and_slide()

.. code-tab:: csharp C#
Expand Down Expand Up @@ -199,11 +195,7 @@ NavigationServer2D and a NavigationAgent2D for path movement.
Vector2 currentAgentPosition = GlobalTransform.Origin;
Vector2 nextPathPosition = _navigationAgent.GetNextPathPosition();

Vector2 newVelocity = (nextPathPosition - currentAgentPosition).Normalized();
newVelocity *= _movementSpeed;

Velocity = newVelocity;

Velocity = currentAgentPosition.DirectionTo(nextPathPosition) * _movementSpeed;
MoveAndSlide();
}

Expand Down
12 changes: 2 additions & 10 deletions tutorials/navigation/navigation_introduction_3d.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,7 @@ a NavigationAgent3D for path movement.
var current_agent_position: Vector3 = global_position
var next_path_position: Vector3 = navigation_agent.get_next_path_position()

var new_velocity: Vector3 = next_path_position - current_agent_position
new_velocity = new_velocity.normalized()
new_velocity = new_velocity * movement_speed

velocity = new_velocity
velocity = current_agent_position.direction_to(next_path_position) * movement_speed
move_and_slide()

.. code-tab:: csharp C#
Expand Down Expand Up @@ -204,11 +200,7 @@ a NavigationAgent3D for path movement.
Vector3 currentAgentPosition = GlobalTransform.Origin;
Vector3 nextPathPosition = _navigationAgent.GetNextPathPosition();

Vector3 newVelocity = (nextPathPosition - currentAgentPosition).Normalized();
newVelocity *= _movementSpeed;

Velocity = newVelocity;

Velocity = currentAgentPosition.DirectionTo(nextPathPosition) * _movementSpeed;
MoveAndSlide();
}

Expand Down
9 changes: 3 additions & 6 deletions tutorials/navigation/navigation_using_navigationagents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ This script adds basic navigation movement to a Node3D with a NavigationAgent3D

movement_delta = movement_speed * delta
var next_path_position: Vector3 = navigation_agent.get_next_path_position()
var current_agent_position: Vector3 = global_position
var new_velocity: Vector3 = (next_path_position - current_agent_position).normalized() * movement_delta
var new_velocity: Vector3 = global_position.direction_to(next_path_position) * movement_delta
if navigation_agent.avoidance_enabled:
navigation_agent.set_velocity(new_velocity)
else:
Expand Down Expand Up @@ -236,8 +235,7 @@ This script adds basic navigation movement to a CharacterBody3D with a Navigatio
return

var next_path_position: Vector3 = navigation_agent.get_next_path_position()
var current_agent_position: Vector3 = global_position
var new_velocity: Vector3 = (next_path_position - current_agent_position).normalized() * movement_speed
var new_velocity: Vector3 = global_position.direction_to(next_path_position) * movement_speed
if navigation_agent.avoidance_enabled:
navigation_agent.set_velocity(new_velocity)
else:
Expand Down Expand Up @@ -271,8 +269,7 @@ This script adds basic navigation movement to a RigidBody3D with a NavigationAge
return

var next_path_position: Vector3 = navigation_agent.get_next_path_position()
var current_agent_position: Vector3 = global_position
var new_velocity: Vector3 = (next_path_position - current_agent_position).normalized() * movement_speed
var new_velocity: Vector3 = global_position.direction_to(next_path_position) * movement_speed
if navigation_agent.avoidance_enabled:
navigation_agent.set_velocity(new_velocity)
else:
Expand Down
2 changes: 1 addition & 1 deletion tutorials/navigation/navigation_using_navigationpaths.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ the default navigation map by setting the target position with ``set_movement_ta

current_path_point = current_path[current_path_index]

var new_velocity: Vector3 = (current_path_point - global_transform.origin).normalized() * movement_delta
var new_velocity: Vector3 = global_transform.origin.direction_to(current_path_point) * movement_delta

global_transform.origin = global_transform.origin.move_toward(global_transform.origin + new_velocity, movement_delta)
4 changes: 2 additions & 2 deletions tutorials/physics/rigid_body.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Here is a custom ``look_at()`` method that will work reliably with rigid bodies:
func look_follow(state, current_transform, target_position):
var up_dir = Vector3(0, 1, 0)
var cur_dir = current_transform.basis * Vector3(0, 0, 1)
var target_dir = (target_position - current_transform.origin).normalized()
var target_dir = current_transform.origin.direction_to(target_position)
var rotation_angle = acos(cur_dir.x) - acos(target_dir.x)

state.angular_velocity = up_dir * (rotation_angle / state.step)
Expand All @@ -58,7 +58,7 @@ Here is a custom ``look_at()`` method that will work reliably with rigid bodies:
{
var upDir = new Vector3(0, 1, 0);
var curDir = currentTransform.Basis * new Vector3(0, 0, 1);
var targetDir = (targetPosition - currentTransform.Origin).Normalized();
var targetDir = currentTransform.Origin.DirectionTo(targetPosition);
var rotationAngle = Mathf.Acos(curDir.X) - Mathf.Acos(targetDir.X);

state.SetAngularVelocity(upDir * (rotationAngle / state.GetStep()));
Expand Down