497009 2 years ago
parent
commit
000c4dce3d
1 changed files with 9 additions and 32 deletions
  1. 9 32
      godot_project/hero_kinematic_body.gd

+ 9 - 32
godot_project/hero_kinematic_body.gd

@@ -1,11 +1,10 @@
 extends KinematicBody2D
 
 #var is_moving = false
-onready var SPEED = 40
+onready var SPEED = 200
 var velocity = Vector2.ZERO
-var point_to_go_to = 0
+var point_to_move_to = null
 
-var path = []
 
 # Add more variables if there are more zones
 var zone_sizes = {1:[Vector2(512, 320), Vector2(-1600, -64), false],
@@ -35,36 +34,14 @@ func pick_random_point():
 	return position_to_go_to
 
 
-func generate_path(path_to_move_to):
-	path = $LevelNavigation.get_simple_path(self.global_position, path_to_move_to, false)
-	print(path)
-	$Line2D.points = path
-
-
-func navigate():
-	if path.size() > 0:
-		velocity = self.global_position.direction_to(path[1]) * SPEED
-		
-		if self.global_position == path[0]:
-			path.pop_front()
-	
-#	print(path[0])
-#	print(hero.global_position)
-
-
-func move_to_random_point():
-#	is_moving = true
+func move_to_point(point_position):
+	var direction = point_position - self.global_position
+	velocity = direction
 	velocity = move_and_slide(velocity)
 
 
-func _ready():
-	point_to_go_to = pick_random_point()
-
-
 func _physics_process(delta):
-#	print(velocity)
-	$Line2D.global_position = Vector2.ZERO
-	if $LevelNavigation != null:
-		generate_path(point_to_go_to)
-		navigate()
-		move_to_random_point()
+	if point_to_move_to == null:
+		point_to_move_to = pick_random_point()
+	
+	move_to_point(point_to_move_to)