- Home /
Changing AI's target in run time
Hello,
I want to know how I can redirect a new point to be the target during run time. I have a BOX with a trigger, once the FPC is colliding with it, it becomes the target of the AI. I've created a child object of the BOX, and now I want the AI to have this child object as a new target and not the FPC.
For example, I have an enemy that is chasing the player once it hits the trigger, but instead I want it to chase the cake that lies near by.
This is how I'm thinking logically:
assign the BOX as an object using the script it has on it (EDIT: assign a class to gameObject).
private ShelfEvent shelf; public Void AssingNewTarget(Vector3 target, Transform point) { shelf = GameObject.FindGameObjectWithTag("Product").GetComponent<ShelfEvent>(); if (shelf != null) { TODO: assign new target } }
reference the child objects of the BOX, and see if they active/ not null?
Then say that FPC transform is no longer relevant but there's a new relevant transform?
I'm literally having a hard time with each step of the way.
EDIT: I've decided for start to assign a regular object and then move to it's child.
why not just make a new empty gameobject as a child of the FPC and have the AI permanently follow it.
Then when you get your trigger. simply re-parent your empty marker to the cake and it's position.
Hi! I love your idea and going to try it!
Answer by JC_SummitTech · Jun 05, 2017 at 07:24 PM
If I understand correctly, you have one player, and N other actors(AI). Whenever the player collides with a trigger, the actors should "target" that trigger.
The way I would do that, is use a MessageHandler singleton. have all AI register to a TargetChanged delegate in the MessageHandler. When the player collides with a trigger, call MessageHandler.TargetChanged(collidedObject.transform);
Your AIs will then be notifiec and can have their target changed appropriately.
Hi @JC_SummitTech I'm having a Final State $$anonymous$$achine for the AI's and haven't thought at all about what you're suggesting, but it seems very interesting. This is a whole new way of coding for me. I really think it could be a delicate solution for many lines of code and looking to read more about it. Can you reference any reading material or tutorial?