<h1>how my characters follow a moving target </h1>
<h1>follow a moving target </h1>
june 10, 2021<br>
#ai #character #movement <br>
<br>
After redesigning movement to support <a href="../210429">patrols</a>, I realized the path remains static even if the target moves. Time to tweak the design and debug. <br>
After redesigning the movement system to support <a href="../entries/210429">patrols</a>, I realized the path remains static even if the target moves. Time to tweak the design again. <br>
<br>
<h2>what must be done </h2><br>
Autopathing to attack targets, skill targets, and item targets still partially rely on an old version of the movement system. Also, characters never update their pathfinding, so they cannot pursue moving targets. With some changes, the movement system can officially support following any of these targets, no matter where they go. <br>
Autopathing to attack targets, skill targets, and item targets still partially relies on an old version of the movement system. Also, characters never update their pathfinding, so they cannot pursue moving targets. With some changes, the movement system can officially support following any of these targets, no matter where they go. <br>
<br>
For now, I'll update the movement system so that the character can autopath after a moving item then pick it up once within reach. Since autopathing to items works identically to the others, the fix for them will be the same, too. <br>
For now, I'll update the movement system so the character can autopath after a moving item then pick it up once within reach. Since autopathing to items works identically to the others, the fix will be the same, too. <br>
<br>
<h2>upgrading the movement system </h2><br>
I can keep the same system more or less, but one function is going to have to be rewritten: the character's path_to_object method. <br>
<br>
Before, it only set the next waypoint and built a path between the character and the waypoint. In order to follow moving targets, it needs to use the goal object itself. Also, it needs to be know when to only rebuild part of the path. <br>
Before, it only set the next waypoint and built a path between the character and the waypoint. <br>
<br>
<h3>old path_to_object </h3><br>
<code># Set Dots Between Character + Given Object<br>
In order to follow moving targets, it needs to use the goal object itself. Also, it needs to be know when to only rebuild part of the path. <br>
<br>
<h3>the character receives a waypoint instead of the target, so he is unaware of his target's movement </h3><br>
It took waypoints instead of the goal in the first place for consistency's sake. Since a target can either be a position (as with click-to-move) or an object (as with autopath-to-item) and the movement system only has one entry point, the old system only accepted objects. So when clicking-to-move, a Position2D waypoint is generated at the global mouse position. <br>
@ -29,23 +44,77 @@ For two, it's bad for performance. Generally, the efficiency of a lightweight Go
<br>
The next playable release after the bingo version will have a teleporting boss, so I'll probably need to be more thoughtful about pathfinding then. For now, though, these two fixes should do it... <br>
Now let's test it. I don't have any items that move around, so I'll quickly throw that in. I'll add some movement based on a sine wave into the _process method.<br>
<br>
<code>var time = 0
func _process(delta):
time += delta
var mod = Vector2(delta, cos(time) * 2)
set_gpos(get_gpos() + mod)</code><br>
time += delta
var mod = Vector2(delta, cos(time) * 2)
<h3>the character never stops autopathing, even after picking up the item </h3>
<br>
Okay, one more fix, then I'll have it. <br>
<br>
Previously, the movement AI relied on conditional statements in its process to detemine arrival at the goal. Instead, the <a href="../210402">achievement system</a> handles arrival for the new movement system. Since the process is called faster than the event handlers can function, the old AI system picked up and queue_free'd the floor item before the new system could recognize it had arrived at the goal. This meant the character never truly arrived and never knew to halt the movement process or clear movement variables. <br>
Previously, the movement AI relied on conditional statements in its process to detemine arrival at the goal. Instead, the <a href="../entries/210402">achievement system</a> handles arrival for the new movement system. Since the process is called faster than the event handlers can function, the old AI system picked up and queue_free'd the floor item before the new system could recognize it had arrived at the goal. This meant the character never truly arrived and never knew to halt the movement process or clear movement variables. <br>
<br>
Moving the conditional statements from _process to the function that handles the outcome of movement events. <br>
<br>
<h3>new result code </h3><br>
<code>#enum MOVED {ARRIVED, NOT_MOVING, TOO_SLOW, WRONG_DIRECTION}<br>
<li>First time going by myself to work on my laptop at the cafe since 2018! They let you go maskless if you're vaccinated and it's usually empty anyway, so I actually got to emote at people. </li>
<li>Finally got to wear my new lipstick, too. Too bad my rosy mauve Rush expired, and Urban Decay's discontinuing their perfect Vice lipsticks. Maybe I should have bought one last bullet, but I couldn't resist a fancy closeout Becca lipstick. Mauve Truffle was out of stock, so I got warm pink Sorbet. I wore it with Looxi Genesis and JD Glow Good Gawd for a silver-lavender eye with a green shift. </li>
<li>First time going by myself to work on my laptop at the cafe since 2018! They let you go maskless if you're vaccinated and it's usually empty anyway, so I finally got to smile at the barista. </li>
<li>Finally got to wear my new lipstick, too. Too bad my rosy mauve Rush expired, and Urban Decay's discontinuing their perfect Vice lipsticks. Maybe I should have bought one last bullet, but I couldn't resist a fancy closeout Becca lipstick. Mauve Truffle was out of stock, so I got pink Sorbet. I wore it with Looxi Genesis and JD Glow Good Gawd for a silver-lavender eye with a green shift. </li>
<li>Let's make a schedule for sewing my new capsule wardrobe: </li>
<li>Today - 泣き虫 cutting done </li>
<li>??? - findings, trims, and accent fabric arrive </li>
<li>June 10 - findings, trims, and accent fabric arrive </li>
<li>whenever Mood coupon is good for - order Penitentiary, 4x2 knit </li>
<li>July 4 - order Penitentiary, 4x2 knit </li>
<li>??? - those arrive </li>
<li>July 4 - 泣き虫 sewing done </li>
<li>July 11 - bomber pattern done </li>
@ -56,14 +56,20 @@ july 1, 2021<br>
<br>
<h3>wednesday, june 9 </h3>
<ul>
<li>Kitty loves supervising all chores, but his favorite is changing the bedding. He loves when I make waves with the sheets. </li>
<li>Finally, the character follows a moving target. </li>
</ul>
<br>
<h3>thursday, june 10 </h3>
<ul>
<li>I got groceries at Target, so I had to peak into the Gamestop next-door. What happened? Even the Nintendo game section is small now, and 70% of the store is dedicated to Star Wars and anime clothes and toys. It's been trending this way for years, but at least they had a wall of Nintendo games before. They only had a few used games and controllers, and I didn't see any consoles at all. It looks like Hot Topic now, minus band merch. </li>
<li>I got groceries at Target, so I had to peak into the Gamestop next-door. What happened? Even the Nintendo game section is tiny now, and 70% of the store is dedicated to Star Wars and anime clothes and toys. It's been trending this way for years, but at least they had a wall of Nintendo games before. They only had a few used games and controllers, and I didn't see any consoles at all. It might as well be Hot Topic now, minus the band merch. </li>
<li>Target had lots of corpo pride displays scattered through the store, but Gamestop didn't have any at all lol. </li>
<li>Blogging </li>
</ul>
<br>
<h3>saturday, june 12 </h3>
<ul>
<li>OBS hasn't been able to capture my windows since around February, so I stopped recording GIFs. (lol) I really do want some GIFs for my dev diary, so after looking around, it's apparently a widespread issue for Linux users with no real fix in sight. Dang, I guess it's a real issue. I'm not a fancy streamer with lots of scenes or anything, so I can just record my screen, but that's not good news for OBS at all. For now, my crops are just going to have be taken from the entire screen instead of just the little window. </li>
<li>At least ffmpeg, though very difficult to write, is able to make nice gifs. If OBS gets worse, I guess I'll have to use it for screen capture, too. </li>
<li>Anyway, now my latest article has a GIF, and I can get rid of the following-moving-target test assets. </li>
I'm a US-based indiedev who's learning to program through game development + web development. My hobbies include enjoy studying Japanese, translating isekai manga for others, and playing 90s/00s CRPGs + JRPGs. <br>
I'm a US-based indiedev who's learning to program through game development + web development. My hobbies include playing 90s/00s RPGs, translating shoujo isekai manga from Japanese to English, and sewing clothes. <br>
<br>
To practice different languages, I bounce among some solo projects in Godot Engine, Java, + Python. My main project is a widely scoped ARPG dungeon crawler called Blessfrey. Hopefully the demo will be ready sometime 2021, so keep watching! <br>
To practice different languages, I bounce among solo projects in Godot Engine, Java, + Python. My main project is a widely scoped ARPG dungeon crawler called Blessfrey. Hopefully some playable releases will be ready sometime 2021, so keep watching! <br>
<br>
Feel free to say hello, especially if you're interested in gamedev, too. <br>