Search Unity

Trigger on Collision not every time why?

Discussion in 'Scripting' started by MrAwesome, Nov 3, 2012.

  1. MrAwesome

    MrAwesome

    Joined:
    Sep 1, 2011
    Posts:
    171
    Code (csharp):
    1. function OnCollisionEnter(theCollision : Collision){
    2.    if(theCollision.gameObject.tag=="Skud") {
    3.      Destroy(gameObject);
    4.    }
    5. }
    Then a game object with the tag Skud, go though it not always destroys, perhaps after 20 gameObejct it will destroy?
    Why?

    the Gameobject Skud going thought the game object with the script, with 10.000 Force
     
  2. MrAwesome

    MrAwesome

    Joined:
    Sep 1, 2011
    Posts:
    171
    Why wont people help me+!
     
  3. MrAwesome

    MrAwesome

    Joined:
    Sep 1, 2011
    Posts:
    171
    I got an anthor problem.

    I want a box go to me. and i am using this code

    Code (csharp):
    1.  
    2. var Target:Transform;
    3.  
    4.  
    5.  
    6. function Update () {
    7.  
    8. transform.LookAt(Target);
    9.  
    10.   transform.Translate(Vector3.forward * Time.deltaTime);
    11. }
    12.  
    But it is keep runing away from me? And i have tried with back, and -vector3.forward, and -vector3.back, nothing helps on it
     
  4. kingcharizard

    kingcharizard

    Joined:
    Jun 30, 2011
    Posts:
    1,137
    this will explain the vector3.forward problem
    its the same as writing
    Code (csharp):
    1. forward = new Vector3(0,0,1);
    if you want a box to come towards you u could use

    Code (csharp):
    1. transform.Translate(target.transform.position - transform.position);
    or switch the position variables if the effect is wrong

    as for your original problem, im not really sure what ur problem is, it seems to me that you are saying it doesn't destroy on collision, try using the like
    Code (csharp):
    1. Destroy(this.gameobject);
    dont know if that will help just a suggestion. its really hard to know what going on and why its not working
     
    Last edited: Nov 3, 2012
  5. MrAwesome

    MrAwesome

    Joined:
    Sep 1, 2011
    Posts:
    171
    OKay now it go towards me, but it is going to fast. I just instant move right on me....
     
  6. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Then make it slower. You could use a variable for that, which you put into the transform.Translate statement. With this variable you can control the speed then. Adding Time.deltaTime could also be a good idea.
     
  7. MrAwesome

    MrAwesome

    Joined:
    Sep 1, 2011
    Posts:
    171
    Could you come with a example of how it could look like?
     
  8. kingcharizard

    kingcharizard

    Joined:
    Jun 30, 2011
    Posts:
    1,137
    you need to learn to do this on your own but i'll show you this once,

    Code (csharp):
    1. transform.Translate(target.transform.position - transform.position * moveSpeed * Time.deltaTime);
     
  9. MrAwesome

    MrAwesome

    Joined:
    Sep 1, 2011
    Posts:
    171
    Okay i have a problem, when i using the transform.Translate, it just freaking out. it doesn't go to me, it just moving rapidly from left and right
     
  10. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Hm, this bit by bit doesn`t really make sense. We cannot teach you how to write code here. Just provide help with specific problems. And that`s usually one problem per thread. We are already at number three. To be continued until you have finished your game i guess. And that`s not how it works, sorry.

    Your problem is that you need one or more good tutorials to help you though the basics. Since you use Javascript, have a look here: http://forum.unity3d.com/threads/156983-Where-can-beginners-find-tutorials-for-Unity-s-JavaScript