You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Migrate_v2.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,6 @@
6
6
*`move_player` function now returns two things, first is new movement data as a table that you should overwrite the old one and second is move result table with the structure like { `position`: next position of game object as vector3, `is_reached`: is game object reached the destination as boolean }
7
7
*`debug_draw_player_move` function now draw game object route through the destination.
# Changelog and migration guild from version 2 to 3
2
+
3
+
* Added ability for game objects to have curved corner paths.
4
+
* Added ability to track game object rotation as move result.
5
+
* Added only one ways routes, and added separate arguments `two_way_route_color` and `one_way_route_color` in `debug_draw_map_nodes` function.
6
+
7
+
<imgsrc="examples/raw/debug_draw_one_way_route.jpg"alt="one way route"style="max-width:100%;" />
8
+
9
+
In the above image green line is a two-way path and the light blue line is a one-way path, a little square is placed on a one-way route near the destination, for example in this image the route is one way from node 5 to 6.
10
+
11
+
* Added separate examples of static and dynamic map nodes.
12
+
* Added documentation for module settings.
13
+
* Added `is_one_way` argument to `map_add_route` function, to able to add just one-way route.
14
+
* Added `is_remove_one_way` argument to `map_remove_route` function, to able to remove just one-way route or both between two nodes.
15
+
* Added `map_remove_node` function to remove a node and it's connected routes to it.
16
+
* Added `map_update_node_position` function to update node positions. now the entire map can move dynamically.
17
+
* Added `map_set_properties` function to replace module default settings.
18
+
*`move_initialize` function gets `initial_face_vector` as a vector3 to calculate game object face direction based on this value. setting this value to `nil` will disable rotation tracking system and `rotation` field in move result table will always be `nil`.
19
+
*`move_player` function no longer needs `threshold` as an argument.
20
+
*`move_initialize` function now gets `settings_go_threshold` as a number and you do need to call `move_initialize` if you want to change it. This allows us to prevent situations that a game object always moves with a moving destination node without reaching it, forever. setting this value to `nil` will fall back to the module default value.
21
+
* Adding `settings_path_curve_tightness`, `settings_path_curve_roundness`, `settings_path_curve_max_distance_from_corner` and `settings_allow_enter_on_route` to `move_initialize` arguments. you can overwrite these values for a single game object by them. setting these values to `nil` will fall back to the module default value.
22
+
* Added `rotation` to move result table that returned from function `move_player` and you can set game object rotation to it.
23
+
* Fixed bug that caused a game object to get stuck in a complex intersection.
24
+
* Added `is_show_intersection` argument to `debug_draw_player_move` function to allow debugger mark/not mark intersections of game object path.
25
+
* version 3 is tagged as `v3` in GitHub repository.
* <ahref="https://github.com/dev-masih/defgraph/blob/master/Migrate_v3.md">**Changelog and migration guild from version 2 to 3**</a>
5
6
* <ahref="https://github.com/dev-masih/defgraph/blob/master/Migrate_v2.md">**Changelog and migration guild from version 1 to 2**</a>
6
7
7
8
This module contains functions to create a world map as a shape of a graph and the ability to manipulate it at any time, easily see debug drawing of this graph and move go's inside of this graph with utilizing auto pathfinder.
8
9
9
10
You can define a graph with several nodes and routes between them and the extension takes care of finding and moving your go inside this graph with just one call inside player update function.
10
11
the gif bellow shows you this exactly when the destination for all red circles is node number 6.
As you can see staying on the routes is the number one rule for red circles and they are going to the destination with minimum distance. all you have seen in this gif except for red circles, drawn by defGraph module and all of them are customizable.
15
16
defGraph is adaptable to map change so even if you add or remove routes in the middle of the game extension tries to find the better road for you.
17
+
also, you can update nodes positions, another word you can have dynamically moving routes ;)
This is a community project you are welcome to contribute to it, sending PR, suggest a feature or report a bug.
20
22
@@ -30,45 +32,139 @@ local defgraph = require("defgraph.defgraph")
30
32
```
31
33
Then you can use the DefGraph functions using this module.
32
34
35
+
[Official Defold game asset page for DefGraph](https://defold.com/assets/defgraph/)
36
+
37
+
## Module Settings
38
+
There are several parameters for the module to works with, you can change these parameters one time for the entire module with `map_set_properties` and let each game object inherit those or set these parameters or each game object with `move_initialize` function. If you choose to not change any of them, the module uses it's own default values.
39
+
#### **Threshold:**
40
+
This `number` value used as detection that an object is on a route or not. It's better to use a bigger value as object speed is getting higher to have better movement experience. The module default value is `1` and minimum for this value should be `1`.
41
+
#### **Path Curve Tightness:**
42
+
This `number` value determines how tight a turn on the path should be. The module default value is `4` and minimum for this value should be `2`.
This `number` value determines how round a turn on a path should be. The module default value is `3`. If this value equals `0` the path will not have any curve and the value of `settings_path_curve_tightness` and `settings_path_curve_max_distance_from_corner` will get ignored. The higher value for roundness will need more processing power especially when your map nodes are dynamically moving.
This `number` value determines the maximum value of a turn distance to a corner. The module default value is `10`. If this value equals `0` the path will not have any curve but you should set `settings_path_curve_roundness` to `0` if this is what you want.
This `boolean` value determines is a game object can enter a map in the middle of a route or is should enter it from corners only. The module default value is `true`.
Set the main path and move calculation properties, nil inputs will fall back to module default values. These values will overwrite default module values.
initialize moves from source_position to a node with an id of destination_id inside the created map
51
-
**arguments:** source_position as vector3, destination_id as number
52
-
**return:** special movement data as table
83
+
Adding a node at the given position (position.z will get ignored).
84
+
#### **arguments:**
85
+
*`vector3` position
86
+
#### **return:**
87
+
*`number` Newly added node id
88
+
89
+
> **Note:** Single nodes with no route attached to them are not participating in any routing calculations and it's better to remove them if you are not using them.
Initialize moves from a source position to destination node inside the created map and using given threshold and initial face vector as game object initial face direction and path calculate settings, **the optional value will fall back to module default values.**
> **Note:** The returned special table consists of combined data to use later in `move_player` and `debug_draw_player_move` functions. If at any time you decided to change the destination of game object you have to call this function and overwrite old movement data with returned one.
calculate movements from current_position of the game object inside the created map considering given speed and threshold, using last calculated movement data
57
-
**arguments:** current_position as vector3, speed as number, threshold as number, move_data as table
58
-
**return:** new movement data as table, move result table like { `position`: next position of game object as vector3, `is_reached`: is game object reached the destination as boolean }
59
-
> **Note:** The returned new movement data should overwrite old movement data. normally this function is placed inside go update function and you can set go position to `position` that is inside move result table. also, you should multiply `dt` with speed yourself before passing it to function.
Calculate movements from current position of the game object inside the created map considering given speed, using last calculated movement data.
135
+
#### **arguments:**
136
+
*`vector3` current_position
137
+
*`number` speed
138
+
*`table` move_data
139
+
#### **return:**
140
+
*`table` new movement data
141
+
*`table` move result
142
+
*`position`: `vector3` next position of game object
143
+
*`rotation`: `quat` next rotation of game object
144
+
*`is_reached`: `boolean` is game object reached the destination
145
+
> **Note:** The returned new movement data should overwrite old movement data. normally this function is placed inside go update function and you can set go position to `position` and rotation to `rotation` that is inside move result table. also, you should multiply `dt` with speed yourself before passing it to function.
0 commit comments