Search Unity

Another possibly stupid question

Discussion in 'Editor & General Support' started by FancyPants, Jul 4, 2005.

  1. FancyPants

    FancyPants

    Joined:
    Jun 30, 2005
    Posts:
    38
    I have taken the ShootBallFPS script, and I am trying to change it to make the instantiated "ball" begin at a different location than the person shooting it. This is because it is colliding with the player model (it's a 3rd person camera angle). So, I am trying to get the projectile to start out a little bit in front of the player. I am having no luck.

    Basically, I want the projectile to start out at +5 units along the local z axis of the "shooter" before going on its way.

    Thanks for any help anyone can offer.
    -Thomas
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Code (csharp):
    1.  
    2. var shoot : Rigidbody = Instantiate (ball, transform.position, transform.rotation);
    3.  
    transform.position is the position where the ball will be spawned.
    You want to transform the local space direction to world space, you can use the TransformDirection function for this.
    So you want to instantiate it 5 units in front:

    Code (csharp):
    1.  
    2. offsetPosition = transform.position;
    3. offsetPosition += transform.TransformDirection (Vector3.fwd * 5);
    4. var shoot : Rigidbody = Instantiate (ball, offsetPosition, transform.rotation);
    5.  
     
  3. FancyPants

    FancyPants

    Joined:
    Jun 30, 2005
    Posts:
    38
    Cool. Thank you that is verry helpful!