Skip to content

Commit 5e002fa

Browse files
committed
npcs can follow paths
1 parent 334d6b5 commit 5e002fa

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

objects/obj_game/Create_0.gml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ var map = new UnityMapImport("test.place", self.meshes);
8989
var seesaw = instance_create_depth(100, 0, -300, obj_3d_seesaw);
9090
seesaw.UpdateCollisionPositions();
9191

92-
var npc = instance_create_depth(-200, 0, -450, obj_npc);
92+
//var npc = instance_create_depth(-200, 0, -450, obj_npc);
9393

94-
npc = instance_create_depth(200, 0, -450, obj_npc);
94+
var npc = instance_create_depth(200, 0, -450, obj_npc);
9595
npc.GetMindReadText = function() {
9696
return "Can someone explain sara's collision code, can someone explain what it does?\n\nfor I followed her video exactly, and it simply won't work, just because!";
9797
};

objects/obj_npc/Step_1.gml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
event_inherited();
22

33
if (keyboard_check_pressed(vk_enter)) {
4-
self.pathfinding = [
5-
self.GetNearestPathfindingWaypoint()
6-
];
4+
var start = self.GetNearestPathfindingWaypoint();
5+
var target = choose(
6+
obj_game.a1,
7+
obj_game.a2,
8+
obj_game.a3,
9+
obj_game.a4,
10+
obj_game.a5,
11+
obj_game.a6,
12+
obj_game.a7
13+
);
14+
15+
var path = obj_game.aquila.Navigate(start, target);
16+
self.pathfinding = path.route;
717
}
818

9-
if (self.pathfinding != undefined) {
19+
if (self.pathfinding == undefined) {
20+
self.xspeed = 0;
21+
self.zspeed = 0;
22+
} else {
1023
var speed_run = 300 * DT;
1124
var speed_walk = 180 * DT;
1225

@@ -17,8 +30,21 @@ if (self.pathfinding != undefined) {
1730

1831
var dist = point_distance(0, 0, dx, dz);
1932

20-
if (dist <= speed_walk) {
21-
33+
// if you're right on top of a node, stop
34+
if (dist <= 0.1) {
35+
dx = 0;
36+
dz = 0;
37+
array_delete(self.pathfinding, 0, 1);
38+
if (array_length(self.pathfinding) == 0) {
39+
self.pathfinding = undefined;
40+
}
41+
// if you're close to a node, set the speed to the vector in the direction of the node
42+
} else if (dist <= speed_walk) {
43+
array_delete(self.pathfinding, 0, 1);
44+
if (array_length(self.pathfinding) == 0) {
45+
self.pathfinding = undefined;
46+
}
47+
// if you're far from a node, set the speed to a vector of the magnitude of the walk speed
2248
} else {
2349
dx /= dist;
2450
dz /= dist;

objects/obj_npc/Step_2.gml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
var potential = new Vector3(self.xspeed + self.x, self.yspeed + self.y + self.radius, self.zspeed + self.z);
22
potential = potential.Add(self.CheckMovingObjects());
33
self.cobject.shape.Set(potential);
4-
var displaced_position = obj_game.collision.DisplaceSphere(self.cobject);
4+
/*var displaced_position = obj_game.collision.DisplaceSphere(self.cobject);
55
66
if (displaced_position == undefined) {
77
self.cobject.shape.Set(potential);
88
} else {
99
self.OnCollision(displaced_position.Sub(self.cobject.shape.position));
1010
self.cobject.shape.Set(displaced_position);
11-
}
11+
}*/
1212

1313
self.x = self.cobject.shape.position.x;
1414
self.y = self.cobject.shape.position.y - self.radius;

0 commit comments

Comments
 (0)