Search Unity

Enemy Sphere Collider

Discussion in 'Scripting' started by Checkpoint71, Sep 26, 2019.

  1. Checkpoint71

    Checkpoint71

    Joined:
    Jul 30, 2019
    Posts:
    6
    I try to use a sphere collider on the enemy with trigger. I thought it would be the best do get what kind of things are nearby. But when i use the sphere collider the shooting from player to enemy with raycast, there are funny differnt things. For example the shooting stays at one enemy even when i moved (shooting forward), or it shoot complete other enemy. If i deactivate sphere collider on enemy, everthing works fine. Does the sphere collider on enemy influence my raycast - and wy? In documentation it says if trigger is enabled physic engine is ignored…??
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    With the physics system you can use Layers and control what collides with what.

    To debug what is actually happen, find all your OnColision-style and OnTrigger-style functions throughout your codebase, as well as any Physics.Raycasts, and use Debug.Log() to print the name of the GameObjects involved, and this can help you identify what is hitting what.
     
  3. Checkpoint71

    Checkpoint71

    Joined:
    Jul 30, 2019
    Posts:
    6
    I tried to find what happens, but do not understand what happens; I have a sphere collider on enemy with trigger; OnTriggerEnter i know player is in range; OnTriggerExit player is out of range, radius is enemySight; Shooting is a raycast to forward; What i do not know, wy it happens that the system dont shoot forward somethimes; the raycast shooting result is differnt as without spehre collider with trigger; i dont understand wy;

    If i deactivate the sphere collider with trigger everything is fine. So my question is: How does the sphere collider with trigger influence the shooting raycast and wy? It should not - or i am wrong?

    For example: i shoot to enemy1 in front of me - it hits enemy2 on the side, but my raycast is forward...how can this happens? Somethimes it shoot like i like, somethimes not;
     
  4. Checkpoint71

    Checkpoint71

    Joined:
    Jul 30, 2019
    Posts:
    6
    ok i was silly - sphere collider was hited from raycast.