Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed all instances of velocity being defined for CharacterBody2D #6862

Merged
merged 3 commits into from Mar 3, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions tutorials/3d/using_transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,15 @@ Jump:
if Input.is_action_just_pressed("jump"):
velocity.y = JUMP_SPEED

velocity = move_and_slide(velocity)
move_and_slide()

.. code-tab:: csharp

// Keep in mind Y is up-axis
if (Input.IsActionJustPressed("jump"))
velocity.Y = JumpSpeed;

velocity = MoveAndSlide(velocity);
MoveAndSlide();

All common behaviors and logic can be done with just vectors.

Expand Down
18 changes: 3 additions & 15 deletions tutorials/physics/kinematic_character_2d.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ little more like a regular game character:
extends CharacterBody2D

const GRAVITY = 200.0
var velocity = Vector2()

func _physics_process(delta):
velocity.y += delta * GRAVITY
Expand All @@ -164,7 +163,6 @@ little more like a regular game character:
public partial class PhysicsScript : CharacterBody2D
{
const float gravity = 200.0f;
Vector2 velocity;

public override void _PhysicsProcess(float delta)
{
Expand All @@ -189,8 +187,6 @@ This adds basic support for walking when pressing left and right:
const GRAVITY = 200.0
const WALK_SPEED = 200

var velocity = Vector2()

func _physics_process(delta):
velocity.y += delta * GRAVITY

Expand All @@ -201,11 +197,8 @@ This adds basic support for walking when pressing left and right:
else:
velocity.x = 0

# We don't need to multiply velocity by delta because "move_and_slide" already takes delta time into account.

# The second parameter of "move_and_slide" is the normal pointing up.
# In the case of a 2D platformer, in Godot, upward is negative y, which translates to -1 as a normal.
move_and_slide(velocity, Vector2(0, -1))
# "move_and_slide" already takes delta time into account.
move_and_slide()

.. code-tab:: csharp

Expand All @@ -216,8 +209,6 @@ This adds basic support for walking when pressing left and right:
const float gravity = 200.0f;
const int walkSpeed = 200;

Vector2 velocity;

public override void _PhysicsProcess(float delta)
{
velocity.y += delta * gravity;
Expand All @@ -235,10 +226,7 @@ This adds basic support for walking when pressing left and right:
velocity.x = 0;
}

// We don't need to multiply velocity by delta because "MoveAndSlide" already takes delta time into account.

// The second parameter of "MoveAndSlide" is the normal pointing up.
// In the case of a 2D platformer, in Godot, upward is negative y, which translates to -1 as a normal.
// "MoveAndSlide" already takes delta time into account.
MoveAndSlide(velocity, new Vector2(0, -1));
}
}
Expand Down
8 changes: 2 additions & 6 deletions tutorials/physics/physics_introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,6 @@ the ground (including slopes) and jump when standing on the ground:
var jump_speed = -1000
var gravity = 2500

var velocity = Vector2()

func get_input():
velocity.x = 0
var right = Input.is_action_pressed('ui_right')
Expand All @@ -457,7 +455,7 @@ the ground (including slopes) and jump when standing on the ground:
func _physics_process(delta):
velocity.y += gravity * delta
get_input()
velocity = move_and_slide(velocity, Vector2(0, -1))
move_and_slide()

.. code-tab:: csharp

Expand All @@ -469,8 +467,6 @@ the ground (including slopes) and jump when standing on the ground:
private float _jumpSpeed = -1000;
private float _gravity = 2500;

private Vector2 _velocity = new Vector2();

private void GetInput()
{
_velocity.x = 0;
Expand All @@ -491,7 +487,7 @@ the ground (including slopes) and jump when standing on the ground:
{
_velocity.y += _gravity * delta;
GetInput();
_velocity = MoveAndSlide(_velocity, new Vector2(0,-1));
MoveAndSlide();
}
}

Expand Down