Orbiting Fishies

So last post I talked about the big fishy, so in this post I’m gonna cover the smaller, but just as important fishy, I think it’s been dubbed cave fish(y). Since I’m the programmer I won’t be talking so much about the look, but more about the movement and “AI”.

Smashing!

An Early choice I made was to have the fish very interactable and leave the door open for more gameplay dynamics, so I wanted the cave fish to be fully physics based (told you I was gonna talk more about this). The fish has a rigidbody2D and a collider, using these for the first iteration I gave the fish the player subbo position and applied force in the direction of the subbo if it was within a certain range.SmashingFish
I tweaked the weight and stuff on the rigidbody to make them feel heavier, and boom! I had a fish that rammed into the subbo and sending it flying into walls. At this point they didn’t deal damage, but they still felt like a hindrance, which plays into my wish to have the doors open for more gameplay dynamics.

Into orbit

A weird “bug” that came out of this was that since the fish didn’t have any drag, and they were just getting force applied towards the subbo, this kinda sent them into orbit around the subbo. Although this is pretty fun to watch, it is not exactly what I was going for.

OrbitFishwArrows
Red = Applied force, Black = Velocity

I was also ignoring rotation at this point, so they were spinning wildly while orbiting. Fixing the orbiting was pretty easy, just giving the fishies some linear drag on the rigidbody stopped them from overshooting that much, and prevented them from flying into orbit.

 

 

You spin me round!

The rotation was a bit harder to do, but I got help from fellow programmer Hamtaro.
I wanted to do the rotation with torque and not transform, sticking with the physics so I could have some funny interactions. Feel free to skip this: I’m getting the angle I wish the fish to rotate too using the method ‘Vector2.SignedAngle’, then I’m getting the difference between the current and target angle using ‘Mathf.DeltaAngle’. The important part here is that ‘SignedAngle’ gives a value between 180 & -180, so I can actually get negative values. So I throw the angle I get from ‘DeltaAngle’ into ‘AddTorque’ and this makes the fishies rotate towards the subbo.
TLDR: I get the angle to the subbo and rotate the fishies using ‘AddTorque’, easy.

This has spawned a fun problem though, if you pass the fish they end up rotating round and swim on their back. For now I’ll just keep it like this, and at a later state I’ll try and implement a flip animation.

Since I’m also using physics for my projectiles, when they hit the fish, they actually spin and fly off, which is a nice effect thanks to using physics. So my fish have a tiny death timer which makes them fly off a little before going *poof*.

Last Thoughts

I like where the  fishies are heading, but I definitely want to give them some more love. But this will do for alpha, I’m more for quantity then quality right now until all the stuff we need is in there, then I can give it some more polish.
Well, that’s it for me, hope whoever got the job of reading this didn’t want to end themselves while slogging through.

 

About Wiktor Ravndal

2017 Programming