Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | gruen |
I tryed to do an pathfinding movement for computer-controlled citizens in my game.
my objects are all the same but diefferent instances. and if an value drops under 5 they search for an other Object to reloard that value. ( if they have to go to toilet, they will )
I worked with this code (attached below). Most of the time it works but without changing anything, sometimes the citizens jumps to an other place and stand there.
i tested it out. i startet the game and it worked. i startet it again and it worked. and i started it again and it suddenly doesnt worked.
so i think i can say 8 times out of ten it works perfektly but 2 times the instances jumpes anywhere and stay there. so i think becaus i didnt changed annything but got also two differen resoults it must be an bug in godot.
here is my code.
extends Sprite
var speed = 400.0
var path = PoolVector2Array()
onready var nav_2d = get_node("../Navigation2D")
onready var toilet = get_node("../../Toilette")
func _ready():
set_process(false)
func _input(_event):
if Input.is_action_just_pressed("ui_accept"):
var new_path = nav_2d.get_simple_path(global_position, toilet.global_position)
path = new_path
set_path(path)
func _process(delta):
var move_distance = speed * delta
move_along_path(move_distance)
func move_along_path(distance):
var start_point = position
for i in range(path.size()):
var distance_to_next = start_point.distance_to(path[0])
if distance <= distance_to_next and distance > 0.0 :
position = start_point.linear_interpolate(path[0], distance / distance_to_next)
break
elif distance < 0.0:
position = path[0]
set_process(false)
break
distance -= distance_to_next
start_point = path[0]
path.remove(0)
func set_path(value):
if value.size() == 0:
return
set_process(true)
Having a shot in the dark: does it change anything if you insert this in _ready
:
path = PoolVector2Array()
Also…
func set_path(value):
if value.size() == 0:
return
set_process(true)
Why is set_path
… not setting path
?
Zylann | 2019-10-14 12:57
unfortunaly it doesnt change anything
that have to be a bug because there is no logical reason for changing that behavier without anny changes on code base.
gruen | 2019-10-14 20:22