Hello, i am trying to detect if the player is colliding with the ground with a sphere cast but i don’t want it to collide with item because it cause player to fly (XR game) so i added a if comparetag = Ground but it’s still colliding with items and i can’t just turn of collision in project settings > physics because i need collisions for my sword etc to work can someone help me?
heres what i did. i created a empty object right under the player and added this code to the main player. all except for the variables under the void update()
public Transform GroundCheck;
public float GroundDistance = 0.4f;
public LayerMask GroundMask;
bool IsGrounded;
IsGrounded = Physics.CheckSphere(GroundCheck.position, GroundDistance, GroundMask);
if(IsGrounded && Velocity.y <0)
{
Velocity.y = -2f;
}
after you did that you reference the empty game object into the script like this you just drag it in to the spot and it should work. also make sure that the game object and the player are connected kinda like this ( or you can just put the ground checker as a child of the player) you also want to put all the things that are on the ground in a layer and set the layer mask to that same layer.