Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Maya Basics & Newbie Lounge (https://simplymaya.com/forum/forumdisplay.php?f=31)
-   -   constraining object to midpoint (https://simplymaya.com/forum/showthread.php?t=31628)

bobsquish 27-12-2008 08:55 PM

constraining object to midpoint
 
Hey,

I have two objects which have aim constraints so they point towards each other and another one in the middle which does the same, however, i want this object to always be in at the midpoint of the first two objects as they move apart.

Thanks,
ben

halfloaf 28-12-2008 07:34 AM

Constraints
 
Hiya,

If I understand you correctly, the best thing to do to get the centre object to always be in the middle of the outer objects would be to create an expression.

Something along the lines where;

Object Left = "object_L"
Object Right = "object_R"
Object Centre = "object_C"

These are just descriptors...your expression would be...

object_C.tx=(object_L.tx + object_R.tx)/2;
object_C.ty=(object_L.ty + object_R.ty)/2;
object_C.tz=(object_L.tz + object_R.tz)/2;

What you're doing is telling object_C (your centre object) to inherit the average value of the translate values (tx, ty & tz) of the left and right objects.

Hope that helps!

-Jacques.

bobsquish 28-12-2008 10:41 AM

Hi, thanks for your help but im very new to maya- how would i enter this command?

Thanks.
Ben

halfloaf 28-12-2008 02:37 PM

Expression editor
 
Hiya,

No probs. You need to go to "Window->Animation Editors->Expression Editor"

Next, give the expression a name in the "Expression Name" field and click "New Expression"

Type in (or copy an paste) the expression in the "Expression" box...and click "Create"

You need to change the "Object_L" etc. for whatever your object is called. So, if you have say two spaceships called "ship1" and "ship2" with a planet in the middle, your first part of the expression would look something like...

planet.tx=(ship1.tx + ship2.tx)/2;

same goes for translate y

planet.ty=(ship1.ty + ship2.ty)/2;

Move one of the outside objects and your centre object will more with it.

I've attached a snapshot.

-Jacques

halfloaf 28-12-2008 02:39 PM

Image
 
1 Attachment(s)
Image attached!

bobsquish 28-12-2008 03:16 PM

Thats Perfect - thanks sooo much!

:)

bobsquish 28-12-2008 04:48 PM

Actually - Ive tried on another piece and the mid piece goes the opposite direction to what i want when i move one of the outer objects- ive looked in the channel box and its translate attributes are the opposite of everything else, how can i change this?

Thanks,
Ben

halfloaf 30-12-2008 08:47 AM

Hmm
 
Hmm,

Can you post an image? Also, you may find that you have frozen transformations on two of the objects and not the other? Are you working with global or local axis points...

I have a suspicion it's the freeze transformations problem...

delete the expression, freeze transformation on the objects and try creating the expression again.

-J


All times are GMT. The time now is 07:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018