Browse Source

:wrench: Replace manual compute by Input.get_vector

But still does not work with Gamepad. Why ?
DricomDragon 1 năm trước cách đây
mục cha
commit
c3228bfe09
1 tập tin đã thay đổi với 3 bổ sung13 xóa
  1. 3 13
      first3d/component/entity/walker/walker.gd

+ 3 - 13
first3d/component/entity/walker/walker.gd

@@ -12,21 +12,11 @@ var target_velocity = Vector3.ZERO
 func _physics_process(delta: float) -> void:
 	var direction = Vector3.ZERO
 
-	if Input.is_action_pressed("move_right"):
-		direction.x += 1
-	if Input.is_action_pressed("move_left"):
-		direction.x -= 1
-	if Input.is_action_pressed("move_back"):
-		direction.z += 1
-	if Input.is_action_pressed("move_forward"):
-		direction.z -= 1
-
-	if direction != Vector3.ZERO:
-		direction = direction.normalized()
+	var ground_velocity: Vector2 = Input.get_vector("move_left", "move_right", "move_forward", "move_back")
 
 	# Ground Velocity
-	target_velocity.x = direction.x * speed
-	target_velocity.z = direction.z * speed
+	target_velocity.x = ground_velocity.x * speed
+	target_velocity.z = ground_velocity.y * speed
 
 	# Vertical Velocity
 	if not is_on_floor(): # If in the air, fall towards the floor. Literally gravity