How to make two object parallel

How to make two object parallel

let say i has two object like picture A. And i need move the cube toward the capsule and it is require cube is parellel to the capsule. (like B)

How i can do it, i had success moved the cube to the capsule, but i can not figure out how i can make it parallel.

thanks you in advise.

more ▼

asked Aug 04, 2011 at 12:23 PM

avatar image

lam meng chun
28 28 21 24

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

2 answers: sort voted first

Set their rotations such that they are parallel. The exact rotations to use will depend on your models, but, for example:

 cube.transform.rotation = capsule.transform.rotation;
more ▼

answered Aug 04, 2011 at 12:30 PM

avatar image

7.4k 67 97 110

this is not working on my case. Actually my object is quite more complicated, i am just use cube and capsule to represent my actual object. Hopefully i can get some idea on make two object parallel.

Aug 04, 2011 at 12:42 PM lam meng chun

It will work, but you need to add whatever rotation would make your models parallel in their unrotated form. That's all "parallel" means: oriented the same way. Perhaps if you shows us those models in unrotated form, we can help further.

Aug 04, 2011 at 01:09 PM Waz
(comments are locked)
10|3000 characters needed characters left

The easiest way is to define a rotation based on the cube, than Slerp the capsule to this rotation (the same can be done to position the capsule) - kind of:

var target: Transform; // drag the cube here var offSet: Vector3(0,5,0); // distance to stop var dock = false; // set this to true to start docking

function Update(){ if (dock){ var pos = target.position + target.TransformPoint(offSet); var rot = target.rotation; rot = rot Quaternion.Euler(0,0,90); // see note transform.rotation = Quaternion.Slerp(transform.rotation, rot, Time.deltaTime); transform.position = Vector3.Lerp(transform.position, pos, Time.deltaTime); } } NOTE:* Set the Euler angles above to define the relative orientation of the capsule (it depends on the cube axes).

more ▼

answered Aug 04, 2011 at 12:47 PM

avatar image

59.2k 39 145 335

I reversed things: you want to dock the cube to the capsule, but I showed the other way around. But the idea still applies.

Aug 04, 2011 at 01:16 PM aldonaletto

yap, i noticed that,i am just stuck in
rot = rot * Quaternion.Euler(0,0,90); still working on figure out the relative orientation. feel free to move on to link below for more detailed about the actual problem. http://forum.unity3d.com/threads/99322-How-to-make-two-object-parallel?p=649934#post649934

Aug 05, 2011 at 01:20 AM lam meng chun

If you are having problems to find the ideal euler angles, there's an easier alternative: child an empty object to the capsule, adjust this object to the position and rotation you want the cube to reach, then drag this object to the target variable. You can zero the offset variable and delete the line with that Euler thing, because the cube will align exactly to the position and rotation of the empty object you've added.

Aug 05, 2011 at 04:13 AM aldonaletto

I saw your model, and I really believe the best way is to add an empty object to the big object to be your grasp reference - you can name it Reference, Handle, whatever.
A good way to do it is:
1- create the empty object (let's call it Handle) and child it to the hand;
2- zero Handle's position and rotation at the Inspector - this will fully align Handle to the hand;
2- place the hand at the desired position/rotation;
3- in the Hierarchy view, move Handle to the target object - this will make the Handle a child of the target without altering its current position.
4- drag Handle to the target variable.

Aug 05, 2011 at 04:35 AM aldonaletto

i did it with ur idea, thanks you very much

Aug 07, 2011 at 10:28 AM lam meng chun
(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



Answers and Comments



asked: Aug 04, 2011 at 12:23 PM

Seen: 1706 times

Last Updated: Aug 07, 2011 at 10:28 AM