Forum begins after the advertisement:
[Part 8] if you hit another wall during a wall jump you get stuck flipped
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 8] if you hit another wall during a wall jump you get stuck flipped
- This topic has 3 replies, 2 voices, and was last updated 3 months, 3 weeks ago by Joseph Tang.
-
AuthorPosts
-
August 27, 2024 at 9:32 pm #15691::
Hey! Heres a fun one. if while you are wall jumping you come into contact with another wall it seems like you get flipped permanently. https://imgur.com/a/koOIYlA – gif of issue
my wall jump code, lmk if you need any other code
<code> void WallJump() { if (isWallSliding) { isWallJumping = false; wallJumpingDirection = !pState.lookingRight ? 1 : -1; CancelInvoke(nameof(StopWallJumping)); } if(Input.GetButtonDown("Jump") && isWallSliding) { isWallJumping = true; rb.velocity = new Vector2(wallJumpingDirection * wallJumpingPower.x, wallJumpingPower.y); dashed = false; airJumpCounter = 0; pState.lookingRight = !pState.lookingRight; transform.eulerAngles = new Vector2(transform.eulerAngles.x, 180); Invoke(nameof(StopWallJumping), wallJumpingDuration); } } void StopWallJumping() { isWallJumping = false; transform.eulerAngles = new Vector2(transform.eulerAngles.x, 0); }</code>
As a note I tried addding the update found here: https://blog.terresquall.com/community/topic/general-issue-with-jumping-walljumping-bat-and-some-questions-2/ that added the jumpRotation float but after doing that when trying to wall jump from left hand walls it made it so that I didn’t jump away, just up so I reverted.
August 28, 2024 at 3:33 pm #15697::Okay, after testing for a bit, I’ve found the issue.
First, the code that I gave, in the link you provided, is for a different case where there was a different
Flip()
method code. I presume that yourFlip()
method uses thelocalScale
of the Player. However, in Part 6 of the series, we actually did change theFlip()
code for the Cinemachine camera, to useeulerAngles
instead of the scale.In other words, don’t worry, your code here is fine if you’re using the scale for
Flip()
.
The issue lies within the first if statement in
WallJump()
.if (isWallSliding) { isWallJumping = false; wallJumpingDirection = !pState.lookingRight ? 1 : -1; CancelInvoke(nameof(StopWallJumping)); }
That one line cancelling
StopWallJumping()
is intended to allow the player to cling to a wall that they reach in the middle of a current walljump.The issue with this, is with the way that we’ve made the flipping of the player in
WallJump()
. We flip the player 180 using theireulerAngles
, which works but we need to reset theeulerAngles
again once the jump is completed. Thus, we reset it inStopWallJumping()
, back to 0.But with that first statement, we stop the process of resetting the player’s eulerangles, and thus the player is reversed completely.
So there’s two things you can try.
- Reset the Player’s
eulerAngles
by calling the same code inStopWallJumping()
in that first if statement. [Just drop this code into the statement]:transform.eulerAngles = new Vector2(transform.eulerAngles.x, 0);
or 2) You can flip the player using
localScale
instead ofeulerAngles
in theWallJump()
.August 29, 2024 at 7:51 pm #15704::hey theanks for looking into this. Interestingly I already have “transform.eulerAngles = new Vector2(transform.eulerAngles.x, 0);” in my stop wall jump.
<code> void StopWallJumping() { isWallJumping = false; transform.eulerAngles = new Vector2(transform.eulerAngles.x, 0); }</code>
is it maybe related to my wall slide code?
<code> void WallSlide() { if(Walled() && !Grounded() && xAxis != 0) { isWallSliding = true; rb.velocity = new Vector2(rb.velocity.x, Mathf.Clamp(rb.velocity.y, -wallSlidingSpeed, float.MaxValue)); } else { isWallSliding = false; } }</code>
adding ‘transform.eulerAngles = new Vector2(transform.eulerAngles.x, 0);’ to the iswallsliding = true section here seems to fix it but maybe that will mess with something later on?
Cheers :)
August 29, 2024 at 7:58 pm #15705::Don’t worry your suggested fix will work, I’ve already explained it in my above comment, but TLDR;
The code in
StopWallJumping()
is correct, but everytime you touch a wall, you stop the method from continuing. In other words, you stop the code that is fixing your player’s rotation whenever you touch a wall while still jumping.So, when you applied your fix to
WallSlide()
, you automatically fix the rotation, so long as you touched the wall, which is fine. - Reset the Player’s
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: