Search Unity

FPS : collision detection not working

Discussion in 'Scripting' started by Braydel, Mar 31, 2014.

  1. Braydel

    Braydel

    Joined:
    Mar 30, 2014
    Posts:
    12
    I want to make it so when the bullet hits the object it will delete the object but i tried everything putting a ridge body on it changing the script more then 5 times and editing the ridge body and trying to make it work without a ridge body adding a ridge body to the bullet and editing the box collider and still nothing is working, if you can help me here that will be grate you can post a message below or message me on Skype cause i really prefer Skype so i can just share my screen. My username is braydel.ritter
     
  2. chrisall76

    chrisall76

    Joined:
    May 19, 2012
    Posts:
    667
    How fast is your bullet moving? If a rigidbody moves too fast, collision will be wonky as one frame it could be in front of the enemy and the next it could be behind it, causing collision to never have happened.
     
  3. Braydel

    Braydel

    Joined:
    Mar 30, 2014
    Posts:
    12
    i have a script that will move it i think it is in meters per second if that is so then it is moving at 42 meters per seccond, my bullet script is here

    var BulletSpeed = 5;
    var BulletDestroySpeed = 5;

    function Start () {

    wait();
    }

    function Update () {
    transform.Translate(Vector3.forward * Time.deltaTime * BulletSpeed);
    }

    function wait(){

    Destroy (gameObject, BulletDestroySpeed);

    }

    but the speed is set to 42
     
  4. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Make sure your collision if you're using OnTriggeEnter has your box collider as a trigger checked.
     
  5. booiljoung

    booiljoung

    Joined:
    May 12, 2013
    Posts:
    57
    Check the target bullet size. Unity physics repeat 50 times per seconds.
     
  6. TalhaDX

    TalhaDX

    Joined:
    Feb 2, 2013
    Posts:
    94
    Hi, i am having the same problem as well. And i think it is because we may not have set the Player, Projectile and then the Enemy in same alignment. As i saw the game while running in design view by changing camera angle.

    so i think it is good that you please repeat here what are the values of x,y,z of all these three objects. this may resolve
     
  7. Braydel

    Braydel

    Joined:
    Mar 30, 2014
    Posts:
    12
    i was using OnTriggerEnter and it doesn't work i put a ridge body on like it is supposed to do and it doesn't work i try it without i tried it with the box collider off and changing every variable i can to try to make it work i change the sped to 1 and it doesn't work still so i just decided to try to get help on here
     
  8. Braydel

    Braydel

    Joined:
    Mar 30, 2014
    Posts:
    12
    my value of x, y, and z shouldn't madder in this situation and i check the collider to make sure it is on the object and i made the collider so it is even farther away and it doesn't work so i know it isn't a x, y and z problem.
     
  9. Braydel

    Braydel

    Joined:
    Mar 30, 2014
    Posts:
    12
    bullet size is 0.06 on every access and it is a sphere and the box is 1 on every access.
     
  10. TalhaDX

    TalhaDX

    Joined:
    Feb 2, 2013
    Posts:
    94
    Then who is going to solve the problem... :( We are stuck here. Don't know what went wrong.
     
  11. TalhaDX

    TalhaDX

    Joined:
    Feb 2, 2013
    Posts:
    94
    hi, every trigger and ever thing is same. May be you i can share you the project and you check, resolve and then share problem + solution with every one. What you say bro.
     
  12. Findo

    Findo

    Joined:
    Mar 11, 2014
    Posts:
    368
    void OnTriggerEnter(Collider c){
    DestroyObject(c.gameObject);
    }

    this is is C#
     
  13. TalhaDX

    TalhaDX

    Joined:
    Feb 2, 2013
    Posts:
    94
    bro still this don't work for me. :( I think someone who has every thing running should see my files and see what may be wrong.
     
  14. TalhaDX

    TalhaDX

    Joined:
    Feb 2, 2013
    Posts:
    94
    May be I caught the Error now:

    I have noticed that when a fire ProjectileFab hits the Enemy or the Enemy hits the Player. An error comes as:

    UnityException: Tag: ProjectileFab is not defined!
    Enemy.OnTriggerEnter (UnityEngine.Collider collide) (at Assets/Scripts/Enemy.cs:40)

    Help plzzzz.
     
  15. Braydel

    Braydel

    Joined:
    Mar 30, 2014
    Posts:
    12
    the error does not pop up when i use java script but it does not work still.
     
  16. Braydel

    Braydel

    Joined:
    Mar 30, 2014
    Posts:
    12
    there is simular coding in java script and i used it it is

    OnTriggerEnter(Other : Collider)
     
  17. Braydel

    Braydel

    Joined:
    Mar 30, 2014
    Posts:
    12
    Okay i have figured out what is going on. The bullet is destroying even though it should be destroying the game object any ideas?
     
  18. TalhaDX

    TalhaDX

    Joined:
    Feb 2, 2013
    Posts:
    94
    I got the solution. we have to add tags of all controls. Add the tag of Enemy and apply it to the enemy. Add tag of player and add it. And check the prefab of projectile in prefab and add its tag as well, then apply it too. and its done. thanks to my friend Humaad from skype... :)
     
  19. Braydel

    Braydel

    Joined:
    Mar 30, 2014
    Posts:
    12
    no i found a solution i found out that you need to disable the trigger on the Collier for both