Ok so I am making a first person game when I jump and collide with the wall the character wallruns this issue occurs like this:
i am running and pressing W and jumped and the wall on the right or on the left the player wallruns along the wall i wrote a code to check for raycasthit on the left or the right and stop the player movement and make him fall but seems like it doesnt work well? like it works when i jump and press A key the player doesnt get stuck on the wall just falls anyways here is my movement script:
#Prevent Wallrun
1 messages · Page 1 of 1 (latest)
void playerMovement()
{
isWalking = false;
isRunning = false;
if (moveDirection != Vector3.zero)
{
if (Input.GetKey(KeyCode.LeftShift))
{
speed = 10;
isRunning = true;
}
else
{
speed = 5;
isWalking = true;
}
}
float horizontalInput = Input.GetAxisRaw("Horizontal");
float verticalInput = Input.GetAxisRaw("Vertical");
// Get the forward and right vectors from the camera
Vector3 cameraForward = playerCamera.transform.forward;
Vector3 cameraRight = playerCamera.transform.right;
// Remove the y-component from forward and right, since we want 2D movement relative to the ground
cameraForward.y = 0;
cameraRight.y = 0;
// Normalize the vectors
cameraForward.Normalize();
cameraRight.Normalize();
// Calculate movement direction based on camera's forward and right
moveDirection = (cameraForward * verticalInput) + (cameraRight * horizontalInput);
moveDirection.Normalize(); // Normalize to ensure consistent movement speed
if (!isGrounded())
{
// Activate raycast if the player is mid-air
RaycastHit wallHit;
if (Physics.Raycast(transform.position, moveDirection, out wallHit, 1.1f))
{
// If a wall is detected, stop horizontal movement but allow falling
float wallAngle = Vector3.Angle(wallHit.normal, Vector3.up);
if (wallAngle > 75f && wallAngle < 105f) // Check for steep walls
{
playerRb.velocity = new Vector3(0, playerRb.velocity.y, 0); // Stop horizontal movement
return;
}
}
}
playerRb.velocity = new Vector3(moveDirection.x * speed, playerRb.velocity.y, moveDirection.z * speed);
}```
Showing a video of the issue would be good
Also, is that ChatGPT code? Do you understand the code?
thats my code yea but i am not like advanced programmer xd
i kept asking chatgpt for help about the wall run issue so it kept changing my code
originally this was my code:
if (!isGrounded())
{
RaycastHit wallHit;
if (Physics.Raycast(transform.position, moveDirection, out wallHit, 1.1f))
{
playerRb.velocity = new Vector3(0, playerRb.velocity.y, 0);
return;
}
}
}
so @timid fable sorry for pinging very sorry
I would start by using a physics material for the rigidbody, and set its friction values to zero (and minimum)
lemme try this
this didnt even come to my mind when i was thinking
omg
it worked
holy
@timid fable
this worked
Nice
thanks so much
Np
appreciate ur help