player cell reset flowdirection
This commit is contained in:
parent
4b53993237
commit
3965b3603a
@ -148,6 +148,9 @@ func _update_flow_field():
|
|||||||
var index = z * grid_size_x + x
|
var index = z * grid_size_x + x
|
||||||
var flow_direction = (target.position - _get_cell_center_with_coordinates(x,z)).normalized() * (cell_size/2)
|
var flow_direction = (target.position - _get_cell_center_with_coordinates(x,z)).normalized() * (cell_size/2)
|
||||||
flow_direction_list[index] = Vector2(flow_direction.x, flow_direction.z)
|
flow_direction_list[index] = Vector2(flow_direction.x, flow_direction.z)
|
||||||
|
var target_index = _get_index_from_position(target.position)
|
||||||
|
flow_direction_list[target_index] = Vector2(0, 0)
|
||||||
|
|
||||||
|
|
||||||
func _draw_debug():
|
func _draw_debug():
|
||||||
if show_grid_center:
|
if show_grid_center:
|
||||||
@ -213,12 +216,18 @@ func _get_cell_center_with_coordinates(x:int, z:int) -> Vector3:
|
|||||||
0,
|
0,
|
||||||
(-half_size_z + (z * cell_size) + (cell_size * 0.5)))
|
(-half_size_z + (z * cell_size) + (cell_size * 0.5)))
|
||||||
|
|
||||||
|
func _get_coordinates_from_position(pos: Vector3) -> Vector2i:
|
||||||
|
return Vector2i(int((pos.x - position.x + half_size_x) / cell_size),
|
||||||
|
int((pos.z - position.z + half_size_z) / cell_size))
|
||||||
|
|
||||||
func _get_index_from_position(pos: Vector3) -> int:
|
func _get_index_from_position(pos: Vector3) -> int:
|
||||||
var x = int((pos.x - position.x + half_size_x) / cell_size)
|
var pos_coord = _get_coordinates_from_position(pos)
|
||||||
var z = int((pos.z - position.z + half_size_z) / cell_size)
|
if _is_coordinate_valid(pos_coord):
|
||||||
if x < 0 or x >= grid_size_x or z < 0 or z >= grid_size_z:
|
|
||||||
return -1
|
return -1
|
||||||
return z * grid_size_x + x
|
return pos_coord.y * grid_size_x + pos_coord.x
|
||||||
|
|
||||||
|
func _is_coordinate_valid(coord: Vector2i) -> bool:
|
||||||
|
return coord.x < 0 or coord.x >= grid_size_x or coord.y < 0 or coord.y >= grid_size_z
|
||||||
|
|
||||||
func get_direction_from_position(position: Vector3) -> Vector3:
|
func get_direction_from_position(position: Vector3) -> Vector3:
|
||||||
var index = _get_index_from_position(position)
|
var index = _get_index_from_position(position)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user