Forum begins after the advertisement:
[Part 8] My slide jump not working
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 8] My slide jump not working
- This topic has 7 replies, 2 voices, and was last updated 8 months ago by Elvin Sim.
-
AuthorPosts
-
April 10, 2024 at 7:54 pm #13819April 10, 2024 at 7:55 pm #13820::
private bool Walled() { return Physics2D.OverlapCircle(wallCheck.position, 0.2f, wallLayer); } 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; } } 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); }
April 10, 2024 at 7:55 pm #13821::[Header("Wall Jump Settings")] [SerializeField] private float wallSlidingSpeed = 2f; [SerializeField] private Transform wallCheck; [SerializeField] private LayerMask wallLayer; [SerializeField] private float wallJumpingDuration; [SerializeField] private Vector2 wallJumpingPower; float wallJumpingDirection; bool isWallSliding; bool isWallJumping;
April 10, 2024 at 7:55 pm #13822::void Update() { if (pState.cutscene) return; if (pState.alive) { GetInputs(); ToggleMap(); Heal(); } UpdateJumpVariables(); UpdateCameraYDampForPlayerFall(); RestoreTimeScale(); if (pState.dashing || pState.healing) return; if (pState.alive) { if (!isWallJumping) { Flip(); Move(); Jump(); } WallSlide(); WallJump(); StartDash(); Attack(); CastSpell(); } FlashWhileInvincible(); }
April 10, 2024 at 7:56 pm #13823April 10, 2024 at 8:19 pm #13824::I also want to ask there is a [SerializeField] private float maxFallingSpeed in the code but in the past video I don’t see this code
April 11, 2024 at 2:04 am #13828::There’s a few possibilities.
1) Your
wallLayer
on your PlayerController.cs and wall object’s Layer is not set.Check the gameobject you are using as your wall in the scene, and check that it’s layer is set to the same layer you put for the
wallLayer
variable on your Player.
2) Your “Wall Check” object is not far enough from your player to reach the wall before the Player’s BoxCollider2D.
Check the position of your Player’s BoxCollider2D and the position of your “Wall Check” object. Ensure that the object is outside the BoxCollider of your Player.
3) Your wall jump works but your sliding isn’t affecting the your fall speed against a wall
Your
wallSlidingSpeed
is, despite being set when created, not at a high enough value to have a significant change in speed.
Someone else had also experienced a seperate bug with the working walljump, i’ve provided an improved code in it too if you want to improve the code as well.
[part 8] walljump bugs
April 11, 2024 at 1:33 pm #13829 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: