Godot Version
4.6.2
Question
how can i create smart navigation with paths(+ to speed) and grass(makes character slower)?
4.6.2
how can i create smart navigation with paths(+ to speed) and grass(makes character slower)?
Use a NavigationRegion and NavigationAgent. As to adjusting speed, it depends on if this is a 2D or 3D game.
It is 2D game, but guy must prioritise paths
This is a really good tutorial on how to do that:
Then for the grass, cover them with an Area2D that changes the player’s speed. Or you can modify the grass tiles in a TileMap to do the same.
I’m doing sandbox game where player changes the map and baking it is awful idea, that’s why navigation poligon does not fit
Sorry, I understood, here is what I have done, but I don’t understand how to change travel cost.(I tried to use node navigation region, but I didn’t understood how to use It from code):
extends TileMapLayer
var nav_pol = NavigationPolygon.new()
var points = PackedVector2Array([
Vector2(-8, -8),
Vector2(8, -8),
Vector2(8, 8),
Vector2(-8, 8)
])
func _ready() -> void:
nav_pol.add_outline(points)
nav_pol.make_polygons_from_outlines()
for tile in get_used_cells():
var tile_inform = get_cell_source_id(tile)
if tile_inform == 0:
get_cell_tile_data(tile).set_navigation_polygon(0, nav_pol)
if tile_inform == 1:
get_cell_tile_data(tile).set_navigation_polygon(0, nav_pol)
# Here i need something like: get_cell_tile_data(tile).set_travel_cost(0.5)