mirror of
https://github.com/stan220/godot-docs.git
synced 2026-09-08 17:28:58 +00:00
add missing brackets in c sharp code
This commit is contained in:
@@ -316,15 +316,23 @@ For example, here is the code for an "Asteroids" style spaceship:
|
||||
public override void _IntegrateForces(PhysicsDirectBodyState2D state)
|
||||
{
|
||||
if (Input.IsActionPressed("ui_up"))
|
||||
{
|
||||
state.ApplyForce(_thrust.Rotated(Rotation));
|
||||
}
|
||||
else
|
||||
{
|
||||
state.ApplyForce(new Vector2());
|
||||
}
|
||||
|
||||
var rotationDir = 0;
|
||||
if (Input.IsActionPressed("ui_right"))
|
||||
{
|
||||
rotationDir += 1;
|
||||
}
|
||||
if (Input.IsActionPressed("ui_left"))
|
||||
{
|
||||
rotationDir -= 1;
|
||||
}
|
||||
state.ApplyTorque(rotationDir * _torque);
|
||||
}
|
||||
}
|
||||
@@ -441,7 +449,9 @@ Or to bounce off of the colliding object:
|
||||
{
|
||||
var collisionInfo = MoveAndCollide(_velocity * (float)delta);
|
||||
if (collisionInfo != null)
|
||||
{
|
||||
_velocity = _velocity.Bounce(collisionInfo.GetNormal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -510,11 +520,17 @@ the ground (including slopes) and jump when standing on the ground:
|
||||
var jump = Input.IsActionPressed("ui_select");
|
||||
|
||||
if (IsOnFloor() && jump)
|
||||
{
|
||||
velocity.Y = _jumpSpeed;
|
||||
}
|
||||
if (right)
|
||||
{
|
||||
velocity.X += _runSpeed;
|
||||
}
|
||||
if (left)
|
||||
{
|
||||
velocity.X -= _runSpeed;
|
||||
}
|
||||
|
||||
Velocity = velocity;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,9 @@ be empty. If it did hit something, it will contain collision information:
|
||||
.. code-tab:: csharp
|
||||
|
||||
if (result.Count > 0)
|
||||
{
|
||||
GD.Print("Hit at point: ", result["position"]);
|
||||
}
|
||||
|
||||
The ``result`` dictionary when a collision occurs contains the following
|
||||
data:
|
||||
|
||||
@@ -508,7 +508,9 @@ Here's the code for the player body:
|
||||
|
||||
// Handle jump.
|
||||
if (Input.IsActionJustPressed("jump") && IsOnFloor())
|
||||
{
|
||||
velocity.Y = _jumpSpeed;
|
||||
}
|
||||
|
||||
// Get the input direction.
|
||||
float direction = Input.GetAxis("ui_left", "ui_right");
|
||||
|
||||
Reference in New Issue
Block a user