On offshoot of this issue.
I'd like to have the AI set up some waypoints between himself and marker 1, then between himself and marker 2. (Eventually, this will cycle among 4 markers, 1-2-3-4-1-2-3-4....)
I've worked through how to set a waypoint at a marker, and even within a radius of a marker. I can also get the direction from the AI to the marker. I'd like to set a waypoint about 20m in front of the AI toward the marker, then as he reaches that one, set another one about 20m beyond that. Alternatively, set a fixed number (let's say 6) waypoints between the AI and the marker. Then, when he reaches the marker delete those waypoints and set another set of waypoints to the next marker.
Any help would be greatly appreciated!
Edit: Oof.
Going back about 20 years to trig.
Plotted out what I think will be the way to go.
Pseudo-codishly:
getPos AI
getPos Marker
subtract marker position select 0 from AI position select 0 yields the difference in X (xdiff)
subtract marker position select 1 from AI position select 1 yields the difference in y (ydiff)
(that gives me the two sides of the right triangle that describes the relative location)
xdiff + ydiff = total diff (absolute value?)
xdiff / total diff = percentage of change component in x (percX)
ydiff / total diff = percentage of change component in y (percY)
(let's say I want to put a waypoint about 20m away)
new x difference = 20 * percX (newXdiff)
new y difference = 20 * percy (newYdiff)
(voila)
new marker/waypoint location = [AI position + newXdiff, AI position + newYdiff, (same z or 0, depending)]
Hey - look! No hypotenuses or old Greek guys named Pythagorus!
Does that at all resemble something that might actually work?
Edit2:
Only thing I'm worried about, but now that I think about it I'm not worried about it, is if there's a negative someplace in the equation. I think the "position" type variable is purely grid - x,y,z will always be positive in that formulation. It is when you get into relative distances/positions, it thinks in terms of +/-x/y/z.
Edit3:
Shit. (Oops - not sure if I can cuss here.)
I just realized that if my AI is at a coordinate position GREATER than the marker - in either plane - I will have to allow for negative values/subtraction. I saw some scripts to help with angles (by Mandoble maybe?) - so I guess I need those?
Or something like figure out which x/y is greater, set a add/subtract variable, then have it trigger the appropriate operations?
NextEdit:
FUUUUCk. (Ooops - sorry again if I can't cuss.)
Resorted to pen and paper.
The subtracting the x/y positions will take care of the pos/neg value, in that THAT difference will have the proper modifier.
So, I think I just need a couple conditionals.
if xdiff < 0
newX = AI position - newXdiff
else
newX = AI position + newXdiff
if ydiff < 0
newY = AI position - newYdiff
else
newY = AI position + newYdiff
new marker/waypoint location = [newX, newY, z]
Ok, now to test. Once I get rid of the headache.
NextEdit:
Yeah, headaches still here.
But, thought of another headache. How can I tell if the marker/waypoint is inside a building such that it will interfere with the AI pathfinding. I'm thinking some variation of nearestobject within a small radius - like 5m - will be able to tell me. Plus, to allow for seamless transitions (or close) I was hoping to have a check and set a new waypoint once the guy is within 5m or so, and if he is, then set delete that waypoint/marker and set a new one. So maybe the pathfinding will take care of itself?
Yeah yeah yeah. Won't know until I try, eh?