- Home /
 
               Question by 
               oliver-jones · Aug 06, 2011 at 12:05 AM · 
                transformparentoffsetz-axis  
              
 
              Offset transform.parent.position - Help
Hello,
I have a projectile that is instantiated from the transform.parent.position and rotation, but I would like to offset the 'Z' position by positive 4.
How would I be able to achieve that?
 function Fire(){
     
     var clone : Rigidbody;
     
     clone = Instantiate(RPGprojectile, transform.parent.position, transform.parent.rotation);
     clone.velocity = transform.TransformDirection (Vector3.forward * 10);    
 }
I tried doing:
 var offset : Vector3;
 offset = transform.parent.position + Vector3(0,0,4);
But then that resets X and Y to 0. I also tried:
  var offset : Vector3;
  offset = transform.parent.position + Vector3(transform.parent.position.x,transform.parent.position.y,4);
But that goes a little funny when I move my character - the X and Y positions seem to change.
Please help.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Heratitan · Aug 06, 2011 at 12:14 AM
Have you tried:
 function Fire(){
     var pos : Vector3
     var clone : Rigidbody;
     pos = Vector3(transform.parent.position.x,transform.parent.position.y,transform.parent.position.z + 4);
     clone = Instantiate(RPGprojectile, pos, transform.parent.rotation);
     clone.velocity = transform.TransformDirection (Vector3.forward * 10);   
 }
I hope this helps.
I have - this does work. BUT - I when I move my character around the projectile spawn is offset -- Is it because its reading Global? For Example... When I start the game and fire - it spawns correctly, when I rotate character to the right, the projectile spawns to the left of me.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                