improved character movement

This commit is contained in:
Vivianne 2023-10-06 02:44:51 -07:00
parent 75ac090453
commit 55fa5111c2
2 changed files with 17 additions and 13 deletions

22
hero.gd
View file

@ -1,13 +1,15 @@
extends RigidBody2D
extends CharacterBody2D
@export var speed = 200.0
@export var speed = 100.0
@export var accel = 1000.0
func _physics_process(delta):
if Input.is_action_pressed("up"):
apply_force(Vector2.UP * speed * delta)
if Input.is_action_pressed("down"):
apply_force(Vector2.DOWN * speed * delta)
if Input.is_action_pressed("left"):
apply_force(Vector2.LEFT * speed * delta)
if Input.is_action_pressed("right"):
apply_force(Vector2.RIGHT * speed * delta)
var movement = Vector2(Input.get_axis("left", "right"), Input.get_axis("up", "down")) * speed
if abs(movement.x) > 0.1 and sign(movement.x) != sign(velocity.x):
velocity.x = 0
if abs(movement.y) > 0.1 and sign(movement.y) != sign(velocity.y):
velocity.y = 0
velocity = velocity.move_toward(movement, accel * delta)
move_and_slide()

View file

@ -22,11 +22,11 @@ position = Vector2(788, 69)
rotation = 1.56094
blackboard = NodePath("../Blackboard")
[node name="Hero" type="RigidBody2D" parent="." groups=["Hero"]]
[node name="Hero" type="CharacterBody2D" parent="." groups=["Hero"]]
position = Vector2(545, 223)
mass = 0.1
motion_mode = 1
script = ExtResource("3_fmhqm")
speed = 2000.0
speed = 300.0
[node name="Body" type="CollisionShape2D" parent="Hero"]
shape = SubResource("CircleShape2D_eiiek")
@ -35,3 +35,5 @@ shape = SubResource("CircleShape2D_eiiek")
texture_filter = 1
scale = Vector2(1.21875, 1.21875)
texture = ExtResource("4_svfrs")
[node name="AnimatableBody2D" type="AnimatableBody2D" parent="Hero"]