#Need help making abilities work together.

1 messages · Page 1 of 1 (latest)

lapis sequoia
#

@wintry hollow made you a thread for the issue per Fogsight's demand

wintry hollow
#

Right.

lapis sequoia
#

you can post all the stuff thats relevant in here now,

#

should stick around a few days to reference back to

wintry hollow
#

UnityChanThumbsUp I'm fine with it

lapis sequoia
#

as complex as ur system is.. i doubt ur gonna get a straight cut answer like right off the bat

#

may be a bit 😓

wintry hollow
#

Yeah i expect that. No worries

#

it's my fault to make that mess anyway

lapis sequoia
#

i mean you get better as u code

#

the next time u make this system or something similar u will have learned from it and it will be cleaner /neater

wintry hollow
#

well... I crammed every abilities inside a single class

wintry hollow
#

[Explanation]

I have few variables for "buffers" which decreases in Update with delta time. From PlayerInputManager, when the button for dash is pressed, an event in invoked which is subscribed by the OnHorizontalDashPerformed method in PlayerAbilities class.

[Inside OnHorizontalDashPerformed method]
If the player is able to dash (which is set to false when dashing is ongoing), the remaining dashes is more than 0 and the dashCooldownCounter (the var that decreases each frame after the dash was performed) is less than 0 and the player isn't already WallSliding or WallGrabbing, and if the Player is in contact with the ground then the dashingTimeCounter will be set to dashingTimeBuffer which will decrease in Update and remaining dashes will decrement. Same logic for the AirDash except it checks if player is not in contact with ground.

For WallDash, if the Player is WallGrabbing then the same logic applies and another var wallDashingTimeCounter is assigned with wallDashingTimeBuffer.

All the "buffers" are always set from the Inspector through serialization while the Counter is decremented with deltatime in Update.

[In Monobehaviour's Update method]
All the Counters are decreased using deltatime here which were assigned to their Buffers when the conditions described above were met.

I check for the facing direction using the input from the PlayerInputManager class. Logic is simple as if the x value is positive then isFacingRight is true and false if negative.

#

_ _
On the part which handles the Dash logic itself, it checks if the Player isn't WallGrabbing, dashingTimeCounter is greater than 0 (which was assigned with the buffer var when the OnHorizontalDashPerformed was invoked) and wallDashingTimeCounter <= 0 (which was assigned with the buffer when the WallDash was performed as explained above) and if those conditions are true then dashingTimeCounter is decremented with deltatime till it reaches 0 and makes one of the checking condition false and stopping the dash. Gravity scale is set to 0 to prevent the player from falling down while dashing, assigning ableToDash as false so that player can't dash again till dash ends (somehow this might be unnecessary because dashCooldownCounter exists for this), and then player is restricted from changing direction while dashing and all the movement and jumping is restricted while dash is ongoing and then finally the Dash() is invoked every frame till dashingTimeCounter hits 0 or less.

In the else If condition, it only checks if player canWallDash and the wallDashingTimeCounter is greater than 0. The same logic as above is done for WallDash well except at the end, WallDash() is invoked every frame instead of Dash().

In the else, it just sets everything back to normal as it means the player is not currently dashing (I have to refactor this part later as it is assigning the values every frame which will interfere with other scripts).

[In Dash and WallDash methods]
It just changes the x velocity of the player in the direction needed and y to 0 for every frame the methods are called.

#

_ _
That's all for the necessary explanation of the entirety on how the code executes for dashing and I don't know how can I terminate the dash in middle of the Update method execution when it touches the wall. Hopefully I can get some solution for this mess i created. Thanks in advance!