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.
Answer by Waz
Aug 04, 2011 at 12:30 PM
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;
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.
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.
Answer by aldonaletto
Aug 04, 2011 at 12:47 PM
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
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).
I reversed things: you want to dock the cube to the capsule, but I showed the other way around. But the idea still applies.
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
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.
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.
i did it with ur idea, thanks you very much
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
To help users post good questions and use the site effectively we have posted a user guide. Please check it out.
Answers and Comments
4 People are following this question.
Unable to link unity(Mac) with Visual Studio(Parallels windwos 8.1)
Alternative for semaphores in Unity?
does a while loop also freeze other scripts?
rotating an object so the face nearest another objects face is parallel
Vector3 parallel move.