[My Dev Journals main page]

Page 1 2 3 4 5 6 7 8 9

 

April 23, 2016

Saturday is here at last! It’s about 12:30 PM as I write this and I am looking forward to implementing the “spooked” behavior of the Wimps. So, let’s keep the babbling up here to a minimum and jump right into the programming.

Implementing The “Spooked” Behavior Of  The Wimpies

Last night, I made sure the foundation of the Wimpy enemies was working well. That put me at a great place to move forward and implement the behaviors necessary to give this enemy a unique personality.

Top of the list is their spooked behavior. What this means is when they detect the player they will react by attempting to flee (and hopefully be obliterated by the player… but still I want to make this scenario interesting and provide at least a bit of challenge for the player).

I spent the first 30 minutes just updating the code (and this dev log screenshot) to support the new enemy including renaming my Configuration settings to be easier to work with. For example, instead of enemy1MoveSpeed I renamed this to enemySentryMoveSpeed. And I also added all of config items for the Wimpy enemy. It doesn’t look as clean in the Editor as I’d prefer but I am not wasting my time to build a custom Inspector just to make the layout look better. That’d be… well… a waste of time right now. May need to do that at some point though.

Alright making good progress on this but it is now 2:00 PM and I need to get out in the sunshine and mow the lawn. Wasn’t sure if I needed to calculate the escape angle myself (you may remember the idea was to move more horizontally the further horizontally the enemy was from the player and more vertically the closer horizontally the enemy was from the player which roughly can be thought of as just getting the angle between the player and the enemy) or if Unity had something to do that for me. So I spent time do some research and found a Vector3.Angle function.

That, I discovered had problems because it only returns an angle from 0 to 180 degrees which of course may not be what is needed (possibly being off my 180 degrees). Doing research on this took me to a post on the Unity forums and an AngleSigned function some kind soul provided. I like to see how things are being done in Unity by other people. At the same time, this is why I often think it is more efficient if I just code it all myself and not try to use much of their API.

Anyway, time to mow the lawn. I will return later.

Okay, the back lawn is mowed. I like to alternate between physical and mental activities on my days off. First, because things need to be done. Second, because getting my head out of the computer and outside working is refreshing. In fact, I came back inside about 15 minutes ago, launched the project & looked at the code… eureka. That was an easy fix.

It is 4:00 PM now. And I just tested my latest update to the Wimpy Reaction. Now I have a foundation in place for this specific behavior.

Obviously, this is not what I want. It is, like I said above, a foundation to move forward.  We can see the Wimpies (after they wake up) see the player and react. However, I see two issues here:

Simply using the angle from the player to the Wimpy as the escape vector causes them to move off in a group and not scatter. This means my original idea to use some horizontal modifier based on the horizontal distance from the player was a good one. I need to implement that.

The Wimpy enemy can only react when it detects the player. As you can see two of the Wimpies did not detect the player at the same time as the others. One did notice the player a bit later and reacted. This also needs to be corrected. Two methods immediately come to my mind. Having the Wimpies scan out using more of a line of sight instead of a single raycast OR having the Wimpies that detected the player alert the Wimpies around them. Both are reasonable solutions.

Now, it is time for some food. Mowing the lawn (yeah I don’t sit on my behind riding around on a tractor) worked up an appetite. Well that and the fact that I have not ate yet today. I’ll be back again later to continue on.

It’s now 10:30 PM and I’ve spent the past 90 minutes or so updating the Enemy behavior. I implemented both of the changes I mentioned earlier. Each Wimpy now scans ahead 60 degrees left to right in front of it rather than just directly in front of it as before. This certainly helps them to detect the player earlier. In addition, I set up a simple alert system.

How that works is each EnemyManager.Update I check one Wimpy enemy to see if is currently in an alerted state evading the player. If so, I then have it alert its neighbors. Then I increment that index (SourceIndex for the Wimpy that will be checked in the same manner in the next update). In this way, all of the Wimpies end up being notified but not simultaneously. Although sometimes, it may seem like that is the case depending on how close they are to each other.

Current result:

Definitely better than before. However, they are still moving based on the angle between them and the player when they were “spooked”. Definitely want to implement the logic I originally planned to take horizontal distance into account. This should cause them to scatter more effectively.

I know it may seem like I am focusing a lot on the enemy behavior. In reality, it hasn’t been that much time and this is the first enemy so a lot of the work done on this one will be useful for the other enemies. Some people spend the most time on music, others on the design document, many seem to spend most of their time on the graphics. We each have our own thing that we feel is most important. I spend the most time on this kind of thing. Getting the AI & interaction to feel right and hopefully be more interesting than what is normally seen.

I think this is it for today. Tomorrow I will definitely finish this behavior.

 

Page 1 2 3 4 57 8 9