x


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.

more ▼

asked Aug 06, 2011 at 12:05 AM

oliver-jones gravatar image

oliver-jones
3.9k 720 1192 698

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Aug 06, 2011 at 12:14 AM

Heratitan gravatar image

Heratitan
344 57 50 56

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.

Aug 06, 2011 at 12:27 AM oliver-jones

PS - My parent is fine, its at 0,0,0

Aug 06, 2011 at 12:27 AM oliver-jones
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2289
x679
x193
x38

asked: Aug 06, 2011 at 12:05 AM

Seen: 3650 times

Last Updated: Aug 06, 2011 at 12:27 AM