SakeTami
absent_dogma
absent_dogma

patreon


Section #2: Closest Move Point Finder

This little case explains how to find the closest point, and then follow the rest of the points based on the character’s "catching" position.

WARNING - In case of you never worked in UE4 or C++ you won't get anything. But anyway, I'll present you a dose of pain from my explanation for sure. Let's start.


Let's assume, that we have some position with exact X,Y and Z of the Breeder (who exactly catches Sasha) on the map (red dot).

Look at first picture named "Top View" in corner.

Here we can see 4 "Move Points" named as 0,1,2,3. Each of them has its own Local coordinates based on blueprint (it's empty inside exept one array named "Move Points" and it's a vector)

Assume again, that we being caught at "Catch Point" (RED fat dot). So, it would be an inappropriate human behavior move to the 0 point consider that the final destination is 4-th point.

So, here we go. We need to define, what is the closest point to follow.

BP#1


Here we make a "Br Move points" (#1 in image) variable, which is that exact Blueprint and we do it in "Breeder's" character blueprint ("Br_CBP" further).

But, we need to open that variable to define, which exact "Breeder" will follow to the vectors (#2), made in "Br_Move points" blueprint(Yes, another one single blueprint).


I guess, it might be little confusing, so here we go to clarify something - IN "Br_CBP" we get LINK (variable) to "Br Move points"(#1) and took "Move points" (variable of "Br Move Points")(#2) from "Br Move Points".

Editor mode (when we see viewport) click on "Br_CBP" and find this line (#3)(might be found in "Details" panel) 

!variable must be public(opened eye by right side in bluprint itself)! Good. We pointed correct Breeder!


When it's done, holy madness begins - we take our "Move points" (#2) Local coordinates (for example local coordinates of point №1 will be 0 0 0 (XYZ)) and transform it (#4) into World (point zero obtain coordinates like X11000 Y3352 Z40 in Return Value)

Than we make array with World coordinates of that points (#5) and get our World coordinates by index separately (#6)

All that was for get a distance beetween "Breeder"(V2) and "Move points" (0 or 1 or 2 or 3 in V1) getting SINGLE number (like distance itself in centimetres)

And... make another array!(#7)


"Hell, Dogma, do you really know what are you doing?"

"Not sure" - I answer. "What I'm really sure you're suffering now".

Inhale, exhale...

It going to be easier from now.

Ready? Continue:


BP #2


1-All that stuff we made earlier.

2-This branch is just for set the FIRST point to follow (first closest one)

Cause my logic starts from "Event Tick" I need this "DoOne"

3-Set the whole array(#3.1) into array variable(setter #3) and name it "Points Array" (for more convenient use).

After that using a node "Min of float array" we find index of min value and make an integer variable "Current Point"(#4) which changes defines by logically choosen "Points Array"(#3) (is it closest? ok go, give him its index)

5- As you see, we take this number to index of node "Get" and WORLD coordinates we performed earlier and deliver it to the socket "Dest" in "Move to Location" Node

First point is good, "Breeder" comes to choosen one.

6-What is the 6-th one? It's a changer. As it logic goes from "Tick Event" it might changes its behavior on each tick.

So here we see the barrier. For example, "Breeder" is walking to the first choosen point and whet the distance between choosen point and him will be less than 200cm process refreshing with new data.

7-Let's see what changes this "data" - a holy "Branch" node (#7) and "Increment" node (#7.1).

Example, again: "More than 200cm? I'm "false" and I perform "Move to Location", which is my first choosen point. Equal? (or less, it will works anyway, it will not miss the 200cm number i believe, though would be better make <=)"

I'm "true" and I perform next sequence: "Current Point" (#3) to "Increment"(#7) here we go now I have increased my "Current Point" to "3(2+1)" for example.

8-This "Branch" is for last point (3-rd), so now "Breeder" go toward last 3-rd point and after that won't be patrolling between 2-nd and 3-rd, cause they two is the closest to each other and stop by this "Branch" condition.


In the end I want apoloize for bad explanation. Genuinely. I am not a teacher, but a have my inspirors in face of you. It like an art. Drowing like you can get it.

If even I could think through to this logic - you're even more so. And make it more polish with "ForEachLoop" for example. I couldn't do.

Plenty of other ways to do what I done. Just showed imperfect mine.

And I believe, it's the way of understanding programming, any person such as you have your own way to get it. Just work, work hard, friend.

I'll do my best to help.

Your Absent Dogma.

Section #2: Closest Move Point Finder Section #2: Closest Move Point Finder Section #2: Closest Move Point Finder

More Creators