Sunday, June 5, 2022
HomeGame Developmentunity - Raycast collision not working

unity – Raycast collision not working


I’ve tried to do a gun mechanic for my 3d sport however after I tried to put in writing ray solid it did not work solely layer that’s printed is 0 although it shoots and will get stopped by an impediment here is the vital code

non-public void Replace()
{
    if (!Enter.GetButton("Fire1") || !(Time.time > nextFire))
    {
        return;
    }
    nextFire = Time.time + fireRate;
    Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.5f));
    laserLine.SetPosition(0, gunEnd.place);
    if (Physics.Raycast(rayOrigin, fpsCam.remodel.ahead, out var hit, weaponRange))
    {
        print(hit.collider.gameObject.layer);
        if (hit.collider.gameObject.layer == enemyLayer)
        {
            //lower enemy well being
        }
        else
        {
            laserLine.SetPosition(1, rayOrigin + fpsCam.remodel.ahead * weaponRange);
        }
    }
}

the entire variables are serialaized on inspector window and no errors have been made . i even checked if the enemy did have a working collider which it did and the layer output was 3(enemy)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments