Forum begins after the advertisement:
[part 8] walljump bugs
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [part 8] walljump bugs
- This topic has 5 replies, 3 voices, and was last updated 5 months, 3 weeks ago by Anuk Thotawatta.
-
AuthorPosts
-
April 8, 2024 at 5:45 pm #13780Anuk ThotawattaParticipant::
When i walljump on a wall thats on the right side of the room mi character flips and can no longer walljump because the wallcheck is flipped. and when i wall jump on the left wall the character doesnt jump sideways like in hollow knight.
April 9, 2024 at 2:54 am #13808Joseph TangModerator::I’ve encountered this problem before and here’s an updated code with an explanation to fix this bug.
In your PlayerController.csvoid 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);
if((pState.lookingRight && transform.eulerAngles.y == 0) || (!pState.lookingRight && transform.eulerAngles.y != 0)) { pState.lookingRight = !pState.lookingRight; int _yRotation = pState.lookingRight ? 0 : 180; transform.eulerAngles = new Vector2(transform.eulerAngles.x, _yRotation); }Invoke(nameof(StopWallJumping), wallJumpingDuration); } } void StopWallJumping() { isWallJumping = false; transform.eulerAngles = new Vector2(transform.eulerAngles.x, 0); }When using
int _yRotation = pState.lookingRight ? 0 : 180;
inWallJump()
, it sets theeulerAngles.y
to either [0] or [180], depending on the Player’slookingRight
bool. The idea is to have the player bounce off the wall and face away from the wall when they do so. The issue with this code is thateulerAngles
aren’t affected by normal forms of rotation, like movement keys in game or the Transform Rotation in the inspector, as can be seen in here: https://docs.unity3d.com/ScriptReference/Transform-eulerAngles.html#:~:text=eulerAngles%20represents%20rotation%20in%20world,localEulerAngles.Rather, they have to be reset by code back to a [0] value / normal to have your Player matching up correctly with your intended actions. Thus, we reset the
eulerAngles.y
to 0 when we write theStopWallJumping()
code, where the player bounces away from the wall and stays that way for the setwallJumpingDuration
before being free to move.
Understanding how Euler Angles work, we can remove the differentiatedpState.lookingRight
code fromWallJump()
as they do not affect theeulerAngles
as intended.
Thus, allowing both directions of wall jumping to bounce off the wall.April 9, 2024 at 12:28 pm #13811Anuk ThotawattaParticipantApril 23, 2024 at 2:40 pm #14179Anuk ThotawattaParticipant::recently had this new bug. when i hit a wall right after wall jumping the sprite faces backwards.
As you can see i accidently hit that platform on the side and my character turns the opposite direction until i restart the game.
April 23, 2024 at 2:50 pm #14180Joseph TangModerator::It’s probably cause you transferred from Walljumping to Wallsliding too fast. What you can do is copy the eulerangle code in the stopwalljumping method, and paste it under the if wallsliding function.
April 23, 2024 at 7:31 pm #14202Anuk ThotawattaParticipant -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: