I am trying to add AI competition to the tutorial gem mining game.
What I want the Ai to do: Find the gameobjects tagged as Jewels, pick them as targets and then launch the claw to collect them.
What i’ve tried so far was detecting the jewels via raycast and finding them via “GameObject.FindWithTag(“Jewel”);” but all my tries couldnt produce the result i was wishing for. Either the “claw” is not launched or it launched, but goes literally nowhere.
As I am still a noob, i would be very thankful for any ideas or explanations how to solve this problem
You are bascially shooting out a “claw” in the 2D environment, “grabbing” the jewels and dragging them to your position - its done via a vector 3 tag detection basically. Now i want an AI opponent to do the same, to add in some competition.
I see, I would make a AI script, and store a array of all the valid targets in it. (I have not read the code but if you already have a array like that you can re use it.)
then make the AI pick one of the targets in the array and get the position (Vector3) from it. once you have the position you just use it the same way as you do when you click.
The question is how the AI knows which object to pick, you could have it completely random, or sort the array based on value of the gem. If you want it to be even more advanced you can also raycast and make sure no crappy items are in the way.
If you don’t want perfect accuracy you can also randomize a small offset and add that to the vector before you sent the claw flying =)