| 1 |
|
| 2 |
|
| 3 |
using _BINDINGS_NAMESPACE_; |
| 4 |
using System; |
| 5 |
|
| 6 |
public partial class _CLASS_ : _BASE_ |
| 7 |
{ |
| 8 |
public const float Speed = 5.0f; |
| 9 |
public const float JumpVelocity = 4.5f; |
| 10 |
|
| 11 |
public override void _PhysicsProcess(double delta) |
| 12 |
{ |
| 13 |
Vector3 velocity = Velocity; |
| 14 |
|
| 15 |
|
| 16 |
if (!IsOnFloor()) |
| 17 |
{ |
| 18 |
velocity += GetGravity() * (float)delta; |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
if (Input.IsActionJustPressed("ui_accept") && IsOnFloor()) |
| 23 |
{ |
| 24 |
velocity.Y = JumpVelocity; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
Vector2 inputDir = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down"); |
| 30 |
Vector3 direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized(); |
| 31 |
if (direction != Vector3.Zero) |
| 32 |
{ |
| 33 |
velocity.X = direction.X * Speed; |
| 34 |
velocity.Z = direction.Z * Speed; |
| 35 |
} |
| 36 |
else |
| 37 |
{ |
| 38 |
velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed); |
| 39 |
velocity.Z = Mathf.MoveToward(Velocity.Z, 0, Speed); |
| 40 |
} |
| 41 |
|
| 42 |
Velocity = velocity; |
| 43 |
MoveAndSlide(); |
| 44 |
} |
| 45 |
} |