added collision
This commit is contained in:
@@ -1,32 +1,39 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class Player : Area2D
|
||||
public class Player : KinematicBody2D
|
||||
{
|
||||
private Vector2 velocity;
|
||||
|
||||
[Export]
|
||||
public int speed = 400;
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void _Process(float delta)
|
||||
{
|
||||
public override void _PhysicsProcess(float delta)
|
||||
{
|
||||
GetInput();
|
||||
MoveAndCollide(velocity * delta);
|
||||
}
|
||||
|
||||
public void GetInput()
|
||||
{
|
||||
velocity = new Vector2();
|
||||
if (Input.IsActionPressed("move_left"))
|
||||
{
|
||||
Position -= new Vector2(speed, 0) * delta;
|
||||
velocity.x -= speed;
|
||||
}
|
||||
if (Input.IsActionPressed("move_right"))
|
||||
{
|
||||
Position += new Vector2(speed, 0) * delta;
|
||||
velocity.x += speed;
|
||||
}
|
||||
if (Input.IsActionPressed("move_up"))
|
||||
{
|
||||
Position -= new Vector2(0, speed) * delta;
|
||||
velocity.y -= speed;
|
||||
}
|
||||
if (Input.IsActionPressed("move_down"))
|
||||
{
|
||||
Position += new Vector2(0, speed) * delta;
|
||||
velocity.y += speed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user