x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Make AI follow an array of objects

I'm making an Car AI and now I need a way to make it go through an array of the same object (target point in that case), however, it will only go to the last point inserted in the level, even if in the Array Vector it does show the position for each point. alt text

alt text

Product Version: UE 4.14
Tags:
car_ai3.png (121.4 kB)
car_ai4.png (292.5 kB)
more ▼

asked Dec 01 '16 at 04:34 PM in Blueprint Scripting

avatar image

Pavomba
45 3 6 11

avatar image Rekenq Dec 01 '16 at 05:30 PM

When you say "follow an array of objects" do you mean you want the car to go to a point, and then the next one and then the next one until it reaches the last point? Or what do you mean exactly?

Also why are you repeating the code you have in the construction script in the Procurar o alvo comment block?

One thing I can tell you is that those connection lines look somewhat troublesome, and the execution lines are all over the place, can't really tell what's going on in your script.

avatar image Pavomba Dec 01 '16 at 06:09 PM

It's to go to a point and then to the next ones as you said.

Sorry about my printscreen, its because the code is rather large, but the part abocve the Get All Actors in the second image is for the car movement.

I repeated because I'm really stuck at what I should do, in order for the Array to store the Target Points in the level, I had to make it in a fuction instead of the Event Graph.

avatar image Pavomba Dec 01 '16 at 06:12 PM

The Get All Actors from the car itself is used to get after the Target Point using the Sphere Raycast, the Get All Actors from the Construction Func is to get the Target Point position and store it into the AlvoArray

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

I can't quite see enough in your screenshots but you should be able to use the "Get" function for each value of the array. For the first point, you would Get 0. After that is reached by the car, you would Get 1. Repeat until you hit the last array index and you would then you start back at 0.

more ▼

answered Dec 01 '16 at 06:48 PM

avatar image

thevfxguy13
369 5 7 19

avatar image Pavomba Dec 01 '16 at 07:34 PM

Here is the full BP for the Car

Procurar o Alvo means Find the Target in PT-BR

alt text

car_aifull.png (784.8 kB)
avatar image thevfxguy13 Dec 01 '16 at 07:46 PM

So starting with the Event Begin, the For Each Loop you have is cycling through all the target points immediately in one tick, resulting in the last one being used. You will need to have your code manually cycle to the next point one the first point is reached.

avatar image Pavomba Dec 01 '16 at 09:26 PM

Interesting, how I could make an approach? Even if I switch to event tick it will game the same result.

I did learn about the Array storing each object of the type with this project of following a spline (but inserted on the same BP as the model)

https://www.youtube.com/watch?v=bJXG8y31bVk

It also does make the use of For Loop and the index.

avatar image Pavomba Dec 01 '16 at 09:29 PM

Oh, I thinking I'm getting the way, switch the loop for an get, althrough I have to specify the index number, it does go to the targetpoint of the array number

avatar image Pavomba Dec 02 '16 at 12:46 AM

BTW, is there a way to reset the loop?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Got it guys, just made the same the same health formula applied to the Index and now I have the car following the target.

Thanks everyone, if you are wondering how to do it, use an event overlap begin on your player controlled pawn and node it to Array Indice (array index)

alt text

car_aifinal.png (394.3 kB)
more ▼

answered Dec 01 '16 at 11:16 PM

avatar image

Pavomba
45 3 6 11

avatar image thevfxguy13 Dec 02 '16 at 01:02 AM

At your branch when you change the index, I would use the function Get Last Index and connect it to the array. If your integer is greater than the Last Index in the array, you set the index integer to 0 to restart the loop.

avatar image Pavomba Dec 02 '16 at 03:20 PM

I created an array of the actor class and inserted into a Length node to give me back an simple variable return of the value, it did work too.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Update: After thinking everything was OK, the cars started to either attemp to make the inverse path after playing a second time in simulation, or even trying to go to the second item in the array in the Standalone play.

I'm wondering if there is still an issue with the get actor

alt text

alt text

alt text

bp_ai.png (144.4 kB)
bp_ai2.png (121.6 kB)
bp_ai3.png (129.9 kB)
more ▼

answered Dec 11 '16 at 09:59 PM

avatar image

Pavomba
45 3 6 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question