- Home /
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.
Answer by Julien-Lynge · Sep 30, 2011 at 04:23 PM
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.
Answer by thkiller · Sep 30, 2011 at 05:59 PM
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 ?
Your answer
Follow this Question
Related Questions
Moving a GameObject to a certain point in world space via script 1 Answer
How to make a projectile fly towards it's target 2 Answers
Shaking GameObject Problem 1 Answer
Dont transform.translate if it will collide with another object 1 Answer
How to make an object go to pre-seted position in world 1 Answer