I want to say that when the character is unhooked from the wall, he has a few milliseconds to jump from nothing and I don’t understand what the problem is, pls help
sorry for bad video quality
if you need more information, tell me
I want to say that when the character is unhooked from the wall, he has a few milliseconds to jump from nothing and I don’t understand what the problem is, pls help
sorry for bad video quality
if you need more information, tell me
Share your code (using code tags from the text ribbon, please). There is no way anyone can realistically help you without seeing what you are already doing.
sure here code
using UnityEngine;
public class Player : MonoBehaviour
{
private float horizontal;
private float speed = 8f;
private float jumpingPower = 16f;
private bool isFacingRight = true;
private bool isWallSliding;
private float wallSlidingSpeed = 2f;
private bool isWallJumping;
private float wallJumpingDirection;
private float wallJumpingTime = 0.2f;
private float wallJumpingCounter;
private float wallJumpingDuration = 0.2f;
private Vector2 wallJumpingPower = new Vector2(8f, 16f);
[SerializeField] private Rigidbody2D rb;
[SerializeField] private Transform groundCheck;
[SerializeField] private LayerMask groundLayer;
[SerializeField] private Transform wallCheck;
[SerializeField] private LayerMask wallLayer;
[SerializeField] private Animator anim;
// Update is called once per frame
private void Update()
{
// Get horizontal input
horizontal = Input.GetAxisRaw("Horizontal");
// Check for jump input and grounded state
if (Input.GetButtonDown("Jump") && IsGrounded())
{
// Apply upward force for jumping
rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
}
// Check for wall sliding and wall jumping
WallSlide();
WallJump();
// Flip the character if not wall jumping
if (!isWallJumping)
{
Flip();
}
// Update animation parameters
SetAnimationParameters();
}
// FixedUpdate is called at a fixed interval
private void FixedUpdate()
{
// Move the character horizontally
if (!isWallJumping)
{
rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
}
}
// Check if the player is grounded
private bool IsGrounded()
{
return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
}
// Check if the player is touching a wall
private bool IsWalled()
{
return Physics2D.OverlapCircle(wallCheck.position, 0.2f, wallLayer);
}
// Handle wall sliding behavior
private void WallSlide()
{
// Check if the player is against a wall, not grounded, and moving horizontally
if (IsWalled() && !IsGrounded() && horizontal != 0f)
{
// Enable wall sliding and adjust vertical velocity
isWallSliding = true;
rb.velocity = new Vector2(rb.velocity.x, Mathf.Clamp(rb.velocity.y, -wallSlidingSpeed, float.MaxValue));
}
else
{
// Disable wall sliding
isWallSliding = false;
}
}
// Handle wall jumping behavior
private void WallJump()
{
// Check if the player is wall sliding
if (isWallSliding)
{
// Set up wall jump parameters
isWallJumping = false;
wallJumpingDirection = -transform.localScale.x;
wallJumpingCounter = wallJumpingTime;
// Cancel any previous wall jump calls
CancelInvoke(nameof(StopWallJumping));
}
else
{
// Decrease the wall jumping counter over time
wallJumpingCounter -= Time.deltaTime;
}
// Check for jump input during wall jump preparation
if (Input.GetButtonDown("Jump") && wallJumpingCounter > 0.001f)
{
// Execute wall jump
isWallJumping = true;
rb.velocity = new Vector2(wallJumpingDirection * wallJumpingPower.x, wallJumpingPower.y);
wallJumpingCounter = 0.001f;
// Flip the character if needed
if (transform.localScale.x != wallJumpingDirection)
{
isFacingRight = !isFacingRight;
Vector3 localScale = transform.localScale;
localScale.x *= -1f;
transform.localScale = localScale;
}
// Stop wall jumping after a short duration
Invoke(nameof(StopWallJumping), wallJumpingDuration);
}
}
// Stop wall jumping state
private void StopWallJumping()
{
isWallJumping = false;
}
// Flip the character horizontally
private void Flip()
{
// Check for direction change and flip the character
if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
{
isFacingRight = !isFacingRight;
Vector3 localScale = transform.localScale;
localScale.x *= -1f;
transform.localScale = localScale;
}
}
// Set animation parameters based on character state
private void SetAnimationParameters()
{
// Check for character movement and update animation parameters
bool isMoving = Mathf.Abs(rb.velocity.x) > 0.1f;
anim.SetFloat("yVelocity", rb.velocity.y);
anim.SetBool("isGrounded", IsGrounded());
anim.SetBool("isMoving", isMoving);
anim.SetBool("isWallSliding", isWallSliding);
}
}
The if statement for wall jumping only cares if wallJumpingCounter is greater than 0.001f.
While isWallSliding is true, wallJumpingCounter gets set to wallJumpingTime (0.2f). When isWallSliding goes false, wallJumpingCounter starts to decrease. This means there will be 200ms after you leave a wall where a wall jump will still be allowed. This acts a bit like coyote time for wall sliding, but it doesn’t sound like it is what you want. I think you should check for isWallSliding in statement on line 115.
I already understood why this was happening, I just reduced the time to a few multimilliseconds in some places, and everything became normal
I already understood why this was happening, I just reduced the time to a few multimilliseconds in some places, and everything became normal