basic player movement

This commit is contained in:
Victor Turgeon
2023-01-14 15:04:44 -05:00
parent 0d3b9e7ba8
commit 99b6f5ed0a
108 changed files with 743 additions and 0 deletions

26
Player/player.gd Normal file
View File

@@ -0,0 +1,26 @@
extends CharacterBody2D
@export var MAX_SPEED = 600.0;
@export var ACCELERATION = 2000.0;
@export var FRICTION = 3000.0;
func _physics_process(delta):
var input_vector = get_input_vector();
apply_movement(input_vector, delta);
apply_friction(input_vector, delta);
move_and_slide();
func get_input_vector():
var input_vector = Vector2.ZERO;
input_vector.x = Input.get_action_strength("move_east") - Input.get_action_strength("move_west");
input_vector.y = Input.get_action_strength("move_south") - Input.get_action_strength("move_north");
return input_vector.normalized();
func apply_movement(input_vector, delta):
if(input_vector != Vector2.ZERO):
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta);
func apply_friction(input_vector,delta):
if(input_vector == Vector2.ZERO):
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta);

27
Player/player.tscn Normal file
View File

@@ -0,0 +1,27 @@
[gd_scene load_steps=5 format=3 uid="uid://b62h0w8gjm6tj"]
[ext_resource type="Script" path="res://Player/player.gd" id="1_mbyc2"]
[ext_resource type="Texture2D" uid="uid://ca2eovotfh6v2" path="res://placeholder.png" id="2_26hmp"]
[sub_resource type="SpriteFrames" id="SpriteFrames_mqbrd"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("2_26hmp")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ng5bv"]
size = Vector2(64, 64)
[node name="Player" type="CharacterBody2D"]
script = ExtResource("1_mbyc2")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
frames = SubResource("SpriteFrames_mqbrd")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_ng5bv")