Search Unity

Shell Ejection problem

Discussion in 'Scripting' started by killerz, May 22, 2011.

  1. killerz

    killerz

    Joined:
    Aug 28, 2010
    Posts:
    32
    Hi all,
    I'm making a FPS game, now, I've made the gun script and all is ok, but I've tryed to insert the shell ejection and I have some problem.

    When I shot I use this code for the shell ejection:

    Code (csharp):
    1.  
    2. Transform bulletBox = Instantiate(BulletBox,ShellSpawnPoint.transform.position,Quaternion.identity) as Transform;
    3.  
    In the BulletBox script I used this code:

    Code (csharp):
    1.  
    2. void Start ()
    3.     {
    4.         Vector3 dir = GameObject.Find("Camera").transform.TransformDirection(new Vector3(0.5f,1f,0));
    5.        
    6.         rigidbody.AddRelativeForce(dir*300);
    7.     }
    8.  
    Why it doesn't add a force on the right of camera?? So, It does it but not in different positions.....
    PS : Sorry for the bad english...
     
  2. cat_ninja

    cat_ninja

    Joined:
    Jul 14, 2010
    Posts:
    197
    Hmmmm why are you doing it that way? Why not just add a relative force when the bullet is shot right after instantiation also since the gun follows the camera, instead of using the camera's right direction why not do rigidbody.AddForce(Vector3.right) It'll always be in the same rotation just move it on the local axis Hope You Get It To Work :D
     
  3. killerz

    killerz

    Joined:
    Aug 28, 2010
    Posts:
    32
    Sorry, this is odd..... I know that your way is right, but it doesn't work.....I'll many ways but all don't work..... I don't know....
     
  4. killerz

    killerz

    Joined:
    Aug 28, 2010
    Posts:
    32
    Yeah, sorry my way is right, the problem was the mesh, I've tryed with a sphere and It worked.... I'll try to make a new shell...