'Raycast only works at a specific height
I want to make a 3D platformer for a school project. Since I'm not that experienced in game development, I followed Plai's tutorial. My biggest problem are that I keep sliding down slopes and the slope detection. It detects the slope only if there's a surface below the slope, the player has some distance from the ground yet is not too far from the ground.
This is the method shown to detect the slope. Tried editing it but nothing seems to work.
if (Physics.Raycast(transform.position, Vector3.down, out slopeHit, playerHeight / 2 * 5f))
{
if (slopeHit.normal != Vector3.up) return true;
}
Color rayColor;
if (slopeHit.collider != null) rayColor = Color.green;
else rayColor = Color.red;
Debug.DrawRay(transform.position, Vector3.down, rayColor);
return slopeHit.collider != null;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
