x


How to make a object translate alonge an other

Hi,

I got 2 gameObject in the scene, the first is a capsule and the second is an cylinder.

i have apply some rotations to cylinder and i want the capsule translate along the 3 axes of the of the cylinder.

how to do ?

thanks.

more ▼

asked Sep 30 '11 at 03:50 PM

thkiller gravatar image

thkiller
1 3 3 3

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

2 answers: sort voted first

You can access the axes of the cylinder with the built-in transform variables forward, up, right, etc.

To translate along the +x axis of the cylinder, for instance, you could do the following:

transform.position += cylinderTransform.forward * distanceToTravel;

Good luck.

more ▼

answered Sep 30 '11 at 04:23 PM

Julien.Lynge gravatar image

Julien.Lynge
7.3k 20 25 49

(comments are locked)
10|3000 characters needed characters left
float distanceToTravelX ,distanceToTravelY,distanceToTravelZ;
    distanceToTravelX = 1f;
    distanceToTravelY = 1f;
    distanceToTravelZ = 1f;
    Vector3 dir ;
    dir = target.forward * distanceToTravelZ + target.up * distanceToTravelY+ target.right * distanceToTravelX;
    transform.Translate(dir * Time.deltaTime);
Is it good ?
more ▼

answered Sep 30 '11 at 05:59 PM

thkiller gravatar image

thkiller
1 3 3 3

(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:

x2074
x1274
x204

asked: Sep 30 '11 at 03:50 PM

Seen: 528 times

Last Updated: Sep 30 '11 at 05:59 PM