I’m trying to use Physics.CheckSphere to ground my character. Problem is, it’s always set to true, and I don’t know why. It did work at one point, so its not impossible, but I must have changed something and forgot, because now this is happening.
Related script:
public CharacterController controller;
public Animator anim;
public CapsuleCollider groundChecker;
public bool isGrounded;
public float vertVel;
public float gravity;
public float jumpForce;
private Vector3 moveVector;
private AnimatorStateInfo currentBaseState;
void Start()
{
anim = GetComponent<Animator>();
controller = GetComponent<CharacterController>();
}
void FixedUpdate()
{
InputMagnitude();
GroundCheck();
if (isGrounded)
{
vertVel = -gravity * Time.deltaTime;
if (Input.GetAxisRaw("JumpKeys") != 0)
{
vertVel = jumpForce;
Debug.Log("I'm Jumping");
}
}
else
{
vertVel -= gravity * Time.deltaTime;
}
moveVector = new Vector3(0, vertVel, 0);
controller.Move(moveVector);
}
void GroundCheck()
{
float radius = groundChecker.radius;
Vector3 pos = transform.position + Vector3.up * (radius * 0.9f);
//returns true if the sphere touches something on that layer
isGrounded = Physics.CheckSphere(pos, radius);
//Debug.Log(radius);
//Debug.Log(pos);
Debug.Log(Physics.CheckSphere(pos, radius));
}
There are a few other parts of the script (the start, the part that handles player movement), but they’re unrelated, and they wouldn’t go into the box for script in the post (first time using the forum, don’t know what it’s called, sorry).
I’ve ran Debug.Log on the individual components of CheckSphere - they work fine. I put the groundChecker capsule collider as a child of the player, so that the character controller collider doesn’t interfere with it. I’ve tried setting the capsule collider to a trigger and back. I don’t know what to do.