|
@@ -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
|
|
@@ -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)
|
|
|
{
|
|
@@ -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
|
|
|
|
|
@@ -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
|
|
|
|
|
@@ -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;
|
|
@@ -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));
|
|
|
}
|
|
|
}
|