🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Jumping, Targeting and more

posted in Project Anima Devlog for project Project Anima
Published May 06, 2021
Advertisement

First things first, before we talk about what is new, we must talk about a problem present in our Movement script from before, a problem that showed up once jumping was implemented.

Trying to move towards a direction, while being blocked by a wall, was causing some jitteriness, and even worse, it was causing us to stick to the wall. So if i jump and press to move forward against a wall, i won't fall.

In order to solve this, a raycast is made towards the direction of the delocation, and if it hits any object that belongs to a layer that blocks movement, we verify if this object is a wall ( based on the angle between the normal of the hit point and its projection on the XZ plane ), and if it is, we don't allow this input to be used. Here is the complete code :

Another important thing to notice here, is that we are now using the player current mass to afect this movement ( that is not considered when using rigidbody.MovePosition ). We do this because in the future we will add to the game magic bullets that increases the players mass, in order to prevent its movement.

Now that this is solved, lets JUMP back to our new things =)

The first one, the new ability to jump, is not something very complex, and is very similar to the Movement script.

The tricky part here is : we can only jump if we are touching the ground, otherwise we would be able to press the jump input all the way to the sky.

Lets take a loot at our code :

Nothing spetacular is happening here. We verify on the physics frame if any input was given during our normal frames, and if so, we verify the jumping logic ( this must go to a propper method later… kinda messy to just let this at the fixed update ). First, we are assuming here that our player's pivot will always be at it's foot, so our raycast must start a little higher than that, otherwise when the player is touching the ground maybe it can start under the ground. With that raycast, defining the layers considered as ground, we can decide if the object is touching the ground or not. So if we are touching the ground and the input is given, can we jump now? Sadly, no. We are allowing some tolerance on what is considered to be “touching the ground”, so if we are able to give the jump input again while the player is leaving this tolerance zone, we would end up with a higher jump ( adding forces ). It is not easy to perform this, but is possible. In order to prevent this i've decided to also impose a vertical velocity constraint. If we had jumped recently, we would have really high vertical velocity upwards, otherwise, we would have little to no velocity, or high downwards velocity (landing). So by applying that constraint, we are able to prevent double jumps, but at the same time we allow the player to jump really soon after landing.

In the previous post i said that the next step would be creating animations… however i've decided that a lot can be done without those for now. So i've started to introduce some scripts and further developed some of them.

The first one is a simple script that allows an object that has a camera to retrieve a target on demand. This target is the one the middle of the screen ( where our crosshair is at ) is hovering at.

The second one is a simple “health-like” script. In this game, health and mana are merged in a single resource, that i've named as Anima. Using skills and receiving damage depletes our Anima, and when it reaches zero the player is considered “dead”. For now what i plan for the concept of the game is that every player is some sort of magic entity, that can only materialize itself because of Anima. Without mana, the players are de-materialized. This “death” is called Candence, and has it own script for now with no implementation, but it's basicly a “death” script.

Two other scripts added but without any implementaton are AegisShield e OccultoIndetectable. The first one being our future shield that depletes anima while active ( Smash Bros style, that blocks everything, but i want to make it visually more interesting, to appear only where it is required to “block” hits). The second one, Occulto, is also an active skill that depletes mana, and may also impose other restraints in the future because it is somewhat OP. Every player will have a minimap and will be able to see even enemy players on this map. Occulto is the only way to hide yourself from this minimap skill.

Along with Anima, Candence, Aegis and Occulto, the last default behaviour/skill every player has is Sagacitas, the minimap. And i've worked on a first version of this one.

For this first version, Sagacitas has no map abstraction, it is basicly a bird-view camera that follows the player, so it is always the center of our minimap.

The minimap itself required little to no code. I've set up a second camera, with orthographic view, to render to a texture, that is then shown with a raw image component. I also apply a simple circular mask to it, using unity mask component. This is the final result :

On the code, i update the position of the minimap camera to follow a “target”, our player. The only other piece of code relevant here is that i also prepared a zoom in and out :

What this do is to set the camera's projection size given predefined min and max values, and a zoom factor that serves as the interpolation value between 0 ( min zoom ) and 1 ( max zoom ).

What i wanted now was to implement the other default skills, however, Aegis and Candence depends on receiving damage, so i will probably start either the Gunner or the Shooter classes.

And thats it for this second update!

Previous Entry Basic movement and camera
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

Latest Entries

Advertisement