I have a piece of code which once it is triggered the AI Destination Setter target changes to a New Destination. My problem is that in the Debug it changes the Destination but in the Inspector during Gameplay when the object is triggered the Target wont change. Any help appreciated. Thanks in advance
So you mean that if you change the inspector to the debug view the target changes properly, but when it is in the normal view it does not?
Does the behaviour destination seem to change even though the inspector does not change (i.e. does it move towards the correct target)?
Thanks for your reply. In the Inspector it wont let me change it during runtime. No it doesn’t move towards the New Target it just keeps moving towards the first target.
Was this in the example scenes or in your scene?
If it was in your scene then it very much sounds like you have another script that is constantly setting the destination. Try to disable other scripts until it doesn’t happen anymore.
Ok ill try it. I am trying it in my Scene. I am doing a Pacman game just to know. This is the part where the pacman eats an energizer and the enemies go to another waypoint
I don’t see anything there that would prevent the pacman from changing its target. However one thing that I do see is that you are calling SearchPath every single frame. Normally the AILerp script will automatically recalculate its path asynchronously a few times per second (controlled by the repath rate field). When you call SearchPath every frame, it is possible that you will call it before the previous path has finished calculating and that will then discard the current path calculation and start a new one. It is possible that it never has time to calculate a path completely and that may cause your agents to never (or very rarely) update their paths. If you have path logging enabled you would have seen this in the console as warning messages.
I would recommend that you remove the SearchPath calls except at times when you really want the agent to recalculate its path immediately.
Furthermore I note that your first script (EatObject) sets the destination of “enemy1”, not the pacman. The destination of enemy1 is also set every frame by the target mover script so any change by the EatObject script would instantly be reverted.
Remove all of them. The AILerp scripts can take care of recalculating their paths themselves. Use SearchPath only if you have for example changed the destination and you want to make it react very quickly (i.e. you don’t want to wait until the next automatic path recalculation). You can control how often they recalculate their paths using the repath rate field.
Well, then your target mover script is incorrect because that script will set the destination of enemy1 to the pacman every single frame. You can’t have both.