I am trying to make a FPS Game. In the Movement.cs. The Raycast starts from the center of the Capsule (player's transform.position) and is sent towards Vector3.down, with the limit of playerHeight / 2 + 0.1f, where playerHeight is the height of the CapsuleCollider of the player (Capsule).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class checkJump : MonoBehaviour
{
private Rigidbody rb;
private float playerHeight = 2f;
private bool isOnGround;
private float jumpSpeed = 400f;
void Start() {
rb = GetComponent<Rigidbody>();
}
void Update()
{
isOnGround = Physics.Raycast(transform.position, Vector3.down, playerHeight / 2 + 0.1f);
Jump();
Debug.Log(isOnGround);
}
void Jump() {
if (Input.GetKeyDown(KeyCode.Space) && isOnGround)
{
rb.AddForce(Vector3.up * jumpSpeed * Time.deltaTime, ForceMode.Impulse);
}
}
}
I disabled all other scripts except "checkJump.cs" one. And when I set the scale value to (4,4,3) or something else, it shows me false in the console and nor does the player Jump when I press Enter. But when I set the scale value to (1,1,1) it shows true. In both cases, the player is on the surface of the ground.
Also tried on another Capsule GameObject, doesn't work.
Here are the images :