Krilling Dev-Log #3 + Movement Experimentation

Published February 04, 2024
Advertisement

Krilling

This week I was tasked with improving the functionality of the pull mechanic. The issue with the pull mechanic was that it would pull the AI directly on top of the object meaning there would just be a large mob of people standing inside of the object.

The goal is to pull the AI to some location near the object but to have that location be random to avoid all of the AI going to the same location. To achieve this, I start from the position of the object and choose a random angle between 0 and 360. I then rotate this angle over and over by a fixed amount until I have rotated it 360 degrees. At each step of this process, I perform a line cast in that angle's direction for a fixed distance to see if there are any objects in the path to this new location. If nothing has been detected, then the discovered location must be a valid location to pull the AI to. This process is repeated every time an AI is pulled with the initial random angle driving the randomness that spreads the AI out.

This was all that was needed to achieve the desired effect. However, I discovered that it felt a bit strange that there was such a large number of victims being pulled to the location when you pressed the button. I decided to add in a percentage chance that an AI is pulled. Whenever a victim enters the pull range I simply generate a random number between 0 and 1 and if that number is larger than some decided value the AI will be pulled to the object.

With both of these parts combined the final result ended up looking like this.

As you can see the AI is much more spread out and some of the AI continue to sit in the chairs and not be pulled. This makes the pull effect feel much more natural as to what a player would expect to happen. That concludes my work this week on The Krilling Project. However, this week I did some experimentation on the side.

Movement Experimentation

A group of us student developers decided to come together and pick a topic in which we would spend time training skills. This time we decided to do a unique movement experimentation. The goal was to just get in the engine and create some unique style of character movement. For my movement system I went with a 2D game with a grappling hook and dash-based movement. The idea was that the player cannot move normally and can only move by using a grappling hook and a small dash. The dash is incredibly limited and is intended to make minor adjustments to the players velocity. The bulk of the focus is on using the grappling hook to move around.

To start I will explain the simpler mechanic, the dash. The dash happens when the player left clicks and the character will dash in the direction of the mouse cursor. The player is only allowed to dash once in the air, but the dash is reset when the player either touches the ground or successfully grapples to something. At a base level this is as a simple as getting the direction the player clicks and adding a force in that direction. This is mostly all that is done, but to make the dash feel better I check for both the x and y direction if it is in the same direction as the velocity. For instance if the y direction is negative, e.g. pointing downwards, and the velocity y component is positive, e.g. traveling upwards, they would be traveling in opposite directions. In this case I subtract the current velocity in that direction from the force being applied. This has the effect of increasing the force in that direction when the player is traveling in the opposite direction from where they want to dash. Without this the player will simply cancel out their velocity with the dash and not move at all. This ensures that the dash travels roughly the same distance every time the button is pressed.

Here is a demonstration of the dash with a much higher force than normal and unlimited dashes to show off this point. The top is without the counteracting opposite forces and the bottom is the improved version with that.

The grappling hook has 2 main parts, shooting, and retracting. The shooting portion can be thought of as a projectile. When the player right clicks a projectile is spawned that travels in the direction of the cursor. Obviously, a grappling hook also has a tether connecting the player to it, this is just a graphical portion that I make by updating the rotation and size of a rectangle every frame to connect the player to the projectile. When the projectile collides with a surface it attaches to the surface and activates the retract mode.

In retract mode the important first step is to limit the player from moving further away from the grapple point and convert the momentum in a circular motion. To achieve this I first take the velocity of the player in global coordinates, and convert it to be in terms of the grapple hooks local rotation. For instance, if the grapple hook is rotated 90 degrees then the y value of the velocity will become the x value of the new velocity, and the negative of the x value will become the y value, essentially rotating the velocity vector 90 degrees. To achieve this unity has a InverseTransformDirection function that can be used to convert a direction in global space to the same direction in local space. After getting this relative velocity I clamp off any velocity in the negative y direction. In other words any velocity traveling away from the hook is counteracted. You can imaging if you have a rope attached to something and carry it traveling in one direction until you reach the length of the rope all of your velocity will be negated instantly. But if you do the same thing by travel at a slight angle rather than perfectly away from the pole, then once you reach the length you will carry some of the velocity in a tangential direction. This is the process I am mimicking here. Velocity in the tangential direction is preserved while velocity in the centrifugal direction is eliminated. Then this clamped velocity will be converted back to world space and set to the velocity of the player.

Here is what that looks like with just this.

Now after that step the final part is to add some velocity in the direction of the grapple point to pull the player towards it. This is as simple as instead of clamping the value to 0, clamping the velocity to some constant value.

This will pull the player towards the hook.

The player also can press space or dash and cancel the hook return but keep the velocity. This is done just by simply removing the hook since the hook is what drives the velocity change, and unity’s rigidbody will take care of the rest. With all of this combined and the dash being back to small and limited the movement can look something like this.

That is all for my work this week. Next week I am going to be working on adding animations to the AI and also assisting with some UI work, so if you are interested in that be sure to check back in after this week for another post.

Previous Entry Krilling Dev-Log #2
Next Entry Krilling Dev-Log #4
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement