Search Unity

Effect trouble

Discussion in 'Scripting' started by tsutttra12, Aug 30, 2011.

  1. tsutttra12

    tsutttra12

    Joined:
    Jun 11, 2011
    Posts:
    37
    hello ive been working on this problem for a few days and ive had no luck. i have a weapons script that instantiates a empty game object from the camera because if i try instantiating it from the muzzle effect spawn its not on target but anyway the bullet is a trigger and what ever it hits it instantiates a dirt particle system. i use it for multiple weapons and with one it collides with something right after it instantiates from the camera and calls the particle effect but there is nothing its colliding with ive checked over and over and for the second weapon the empty bullet will just fall to the grown because when i pause and look around the particle system will be down by my feel. any ideas
     
  2. Catsoft-Studios

    Catsoft-Studios

    Joined:
    Jan 15, 2011
    Posts:
    702
    Wow, I could understand nothing but "you have a camera from where you instantiate something with bullets and..."? Try to organize your text. And if you have time, a picture would help a lot.
     
  3. tsutttra12

    tsutttra12

    Joined:
    Jun 11, 2011
    Posts:
    37
    ok well basically what im asking is if anyone has any idea what could be wrong i had to give all the details of the problem or else no one would have any idea what the problem is. but ill say it again the bullet comes instantiates from the camera and once it collides with something it plays a hit sound and a particle effect but as soon as the bullet is instantiated it collides with something but ive checked everything in the scene and nothing is in the way
     
  4. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    Add:

    Code (csharp):
    1.  
    2. function OnCollisionEnter(collision : Collision) {
    3.     print(collision.gameObject.name);
    4. }
    5.  
    or just the print part to your collision enter. This will tell you what the bullet is hitting.

    I do bullets a little different. They are game objects with no colliders and I do a Linecast in the Update to see if they hit anything.

    Code (csharp):
    1.  
    2. private var lastPosition=Vector3.zero;
    3.  
    4. function Update() {
    5.     if(lastPosition==Vector3.zero) lastPosition=transform.position;
    6.     var hit : RaycastHit;
    7.     if(Physics.Linecast(lastPosition, transform.position, hit)){
    8.         print(hit.collider.gameObject.name);
    9.     }
    10. }
    11.  
    You can then do a check to make sure it is not hitting the player and do damage to someone or something.

    I created a thread for just this event.

    http://forum.unity3d.com/threads/101613-Simple-Weapons-shooting-health-and-XP