- Home /
Question by
its_ya_studio · Mar 05, 2021 at 01:50 PM ·
raycastlayers
raycast is hitting the wrong things
i'm using a raycast to get the gameobject its hitting but its hitting the player object itself even tho i have in the unity editor on "ground mask" that it should ignore the player
code for context: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class itemPickup : MonoBehaviour { public Transform camera, looking; public LayerMask GroundMask; public float MaxRayValue = 1f;
private GameObject holding;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
private void FixedUpdate()
{
}
void Update()
{
if (Input.GetKeyDown("e"))
{
raycast();
}
}
void raycast()
{
RaycastHit hit;
if (Physics.Raycast(camera.position, camera.forward, out hit, MaxRayValue))
{
Debug.DrawRay(camera.position, camera.forward, Color.yellow);
Debug.Log(hit.transform.gameObject.name);
holding = hit.transform.gameObject;
}
}
}
Comment
Best Answer
Answer by AbandonedCrypt · Mar 05, 2021 at 01:57 PM
You don't use the ground mask in your raycast.
my god am i not sharp today. thank i totally didn't see it