Almost Figured it Out! My experience in this lecture

When we got to the challenge section of this lecture, I was a little confused how to replicate the InteractWithCombat() method because I thought, “why on earth would I need to use a for loop for movement? There’d be endless RaycastHit hits!” So like a real noob programmer, I started writing a foreach loop for InteractWithMovement() anyway, copying InteractWithCombat()'s code almost line-for-line, spending a half-hour wondering how to get the damned thing to work.

Then, it occurred to me—why not just use the variables from MoveToCursor()?

But Tryndamere, how do I use variables from another method? If I just steal them, I have redundant code, and there’s something I ought to do about that, right? I asked myself the same thing, so I just ripped the variables from MoveToCursor() and tried to figure things out from there. I kept getting stuck, though, thinking it would be better to make MoveToCursor() into a bool as well. So I erased the stolen variables I put in InteractWithMovement() and put them back into MoveToCursor(). I tried setting the value of InteractWithMovement() in here, and realized that didn’t work.

I even tried to do some fancy work with GetMouseRay() inside of InteractWithMovement() to see if I could cheat the system, see if I could access the NavMesh and detect if the mouse ray collided with the NavMesh, and if not, return false. I remember frantically googling “is navmesh gameobject unity” until I realized a NavMesh is static and can’t be declared as a variable anyway. The last thing I tried was returning to the foreach loop and replacing the CombatTarget target variable by making a GameObject destination variable and checking if a ray passed through that, but still no dice.

No matter what I did, when I played the game, I saw Nothing to do. for what seemed like days, endless streams of inaction and confusion. I was all over the place with it, coming up with complicated solutions that teetered on the edge of getting it, coming so close but feeling so far away. I

And so I checked the video for hints. Who knew it would be as simple as just removing the MoveToCursor() method entirely and using its code for InteractWithMovement() instead? Golly gee, I hope I can figure things out better in the future, because I felt pretty dumb after that one.

1 Like

Yeap. Reminds me doing the challenges. I always thought two steps a head and sometimes that meant I over-did the challenge to where it was probably too much for something so simple. Other times the challenges were just over my head and didn’t even attempt them after a first try.

But what mattered to me is that I tried… and thats all they ask for you to do is try.

I’m going to go out on a limb and say that you learned a lot on this side detour. It’s ok to experiment, even when it breaks things (Especially when it breaks things, we sometimes learn more from failure than success). We’ll always give you our way to the challenge, but I’m going to let you in on a big secret. There are many paths to the same goal. We don’t always present the perfect solution, and there is a lot of room in the courses for optimization (Caching references in Awake() instead of spamming GetComponent() in Update loops comes to mind)

Privacy & Terms