[ADD] moving player
This commit is contained in:
parent
1c527b1a0d
commit
a40d9511b7
10
Scene/Player.tscn
Normal file
10
Scene/Player.tscn
Normal file
@ -0,0 +1,10 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Placeholder.png" type="Texture" id=1]
|
||||
[ext_resource path="res://Scripts/Player.gd" type="Script" id=2]
|
||||
|
||||
[node name="KinematicBody2D" type="KinematicBody2D"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 1 )
|
||||
@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://icon.png" type="Texture" id=1]
|
||||
[ext_resource path="res://Scene/Player.tscn" type="PackedScene" id=1]
|
||||
|
||||
[node name="icon" type="Sprite"]
|
||||
position = Vector2( 42.1349, 68.6664 )
|
||||
texture = ExtResource( 1 )
|
||||
[node name="World" type="Node2D"]
|
||||
|
||||
[node name="KinematicBody2D" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 121.087, 85.6409 )
|
||||
|
||||
30
Scripts/Player.gd
Normal file
30
Scripts/Player.gd
Normal file
@ -0,0 +1,30 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
const MAX_SPEED = 200
|
||||
const ACCELERATION = 1000
|
||||
const FRICTION = 1000
|
||||
|
||||
var vel = Vector2.ZERO
|
||||
|
||||
#onready var animationPlayer = $AnimationPlayer
|
||||
#onready var animationTree = $AnimationTree
|
||||
#onready var animationState = animationTree.get("parameters/playback")
|
||||
|
||||
func _physics_process(delta):
|
||||
var input_vector = Vector2.ZERO
|
||||
|
||||
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
|
||||
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
|
||||
|
||||
input_vector = input_vector.normalized()
|
||||
|
||||
if input_vector != Vector2.ZERO:
|
||||
# animationTree.set("parameters/Idle/blend_position", input_vector)
|
||||
# animationTree.set("parameters/Run/blend_position", input_vector)
|
||||
# animationState.travel("Run")
|
||||
vel = vel.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
|
||||
else:
|
||||
# animationState.travel("Idle")
|
||||
vel = vel.move_toward(Vector2.ZERO, FRICTION * delta)
|
||||
|
||||
vel = move_and_slide(vel)
|
||||
Loading…
x
Reference in New Issue
Block a user