- Home /
Other
Set AI Destination Setter target from Script
Hi, I have the following piece of code when the Pacman hits an Energizer gets destroyed and the target needs to be changed so the enemies wont follow the pacman anymore. What should i add to this code pls cause at the moment the target is not being changed? Thanks
I had the same problem. You can't change the target by referencing the destination setter(or at least I couldn't), but you can create an empty object, code that object to identify and move towards/teleport to the desired target. Then you just put the empty object as the target for the destination setter. I know this isn't the most professional solution, but it works.
Answer by xxmariofer · Jan 22, 2019 at 10:07 AM
Cant understand your code, i imagine that script is in the cherry, and i imagine the cherry doesnt have a component of AIDestinationSetter and even if it has one you are destroying it, i imagine you should be using
aIDestinationSetter.target = enemyFollow;
siince i imagine thats a reference to the script you want to access.
Answer by ray2yar · Jan 22, 2019 at 10:38 AM
Have you used debugging to verify that the destinationsetter gets the information to begin with?
Also, if your target is moving you have to continually update the AI target with a different vector3
Yes that's my second step to make the Enemies move in different directions. but it's difficult to find examples on how to implement it
Well, even though you're making a 2d game you can still use unity's navmesh (there might even a 2d version of it). Anyways, in Fixedupdate use agent.setdestination = target.position
Follow this Question
Related Questions
Randomly Spawning 4 cherries in Pacman game (Unity) 1 Answer
Distribute terrain in zones 3 Answers
Looping Between Waypoints 1 Answer
A* Pathfinding Project Y-axis movement, help. 1 Answer
Adding Wander option to AI 1 Answer