Owlets Follow the Player

This week I’ve worked on a lot of things, not to say that I haven’t worked on a lot of things the other weeks but whatever…

Since I’ve talked about the owlets before and since I’ve been the one in our group working on their functionality I decided to continue talking about them and how I made them follow the player around after you’ve picked them up.

 

So according to the concept document the owlets were suppose to follow the player like a snakes tail after you pick them up, something that I didn’t find to hard to make, however it did take a couple of hours to complete and I got quite happy with the result.

Unfortunately I still can’t make gifs for some reason so this image with quality drawn paint arrows will have to do to showcase how it looks:

3775664281982929af369945fd2c90ae

The way it works is that I create a array of owlets and a int that acts like a counter on how many owlets the player have picked up. Whenever the player collides with a owlet a function in the owlet is called, this function switches the owlets state from “idle” to “following” (or rather change a bool called “isIdle” from true to false). It also checks how many owlets the player have picked up earlier, put it self in the correct place in the array and then assign the owlet before it as its follow target. If the player however haven’t picked up any owlets yet its follow target become the player. In order to propperly assign its target the owlet look for the owlet before it self in the array.

In order to create the snake tail effect I added acceleration in the y-axis. This is done by calculating the difference in the y-axis between the owlet and its target, the higher it is the higher the acceleration is and the lower it is the lower the acceleration is.

334cd58cdc50ef31c157a20f39370df5

To explain the image above.

yCurrent is at first the owlets current position. yCorrect is the owlets target position. (Both in the y-axis only!)

yDif is the difference in the y-axis. I then update yCurrent depending on if the owlet is above or below the target where I either add or subtract its value by one plus the acceleration, using “abs” before yDif makes the variable always positive, I did this since it sometimes freaked out otherwhise. I’m sure there are other ways to get the same effect without using abs, possibly by playing around with the “+” and “-” in the code however this was the way I had in mind so it was what I went with. I also found it easier to calculate this in my head when I could rely on yDif being positive no matter what.

After doing the calculation i change the owlets y-position to the updated yCurrent.

Leave a comment