DevLog1: Main Player Movement and jump mechanics


To create the movement mechanic in the player, I needed to bring the illusion of movement with multiple animations tailored to the context of the player character. This means adding multiple frames per '.anim' file to simulate movement when the GameObject is moving right or left, jumping and falling  animation. For this purpose I scripted a basic 2D scroller movement using the Input manager to link a public floating point variable speed and  direction values (Ranging from -1 to 1) to the '.velocity' property from the Rigidbody2D component (Invoked on start), and input modified on update. Simultaneously, I invoked the animator component on start and set boolean and floating point parameters to trigger these animation events on update so these elements matched correctly to the context  of the  player gameobject.  All these elements and transitions were coordinated from the AnyState  state. The jumping mechanic was implemented by using the AddForce method from the RigidBody2D component so on input a floating point magnitude is applied on the '.y' axis of the Vector2  type component on the gameObject. Initially the code structure did not allow me to limit the jumping sequences, which was one of the comments I received as feedback along with animation timing. In order to limit the number of jumps to a single action once on air, I needed to include a boolean field that was modified using an OnCollisionEnter2D function, via a CompareTag method that checked for a gameObject tagged as ground. Once the player jumps the collision is no longer detected and the boolean returns a false value that limits the mechanic to a single action.  Regarding the animation issue, fine tuning was achieved by modifying the speed of the animation on the '.anim' file in the inspector and modifying the jumping force so the fall occurred during the fall of the player.

References:

Jumping

MoreBlakeyyy. (2022, October 20).  2D Jump in Unity in Under 1 Minute. [Video]. YouTube.

https://www.youtube.com/watch?v=QXB4EAyYD8w

Single action Jumping sequence 

Molina, J. (2020, December 29). How do I limit a GameObject to jump only Once? Stack overflow. https://stackoverflow.com/questions/65488572/how-do-i-limit-a-gameobject-to-jump...

Files

Rune Caster Movement progress Play in browser
Sep 06, 2023

Get Codename: Rune Caster

Leave a comment

Log in with itch.io to leave a comment.