SM Forums / Maya Questions / Animation / orbiting expression 
Animation Animation & Rigging Related Topics 
Join the conversation. Reply to post 

Thread Tools 
17012008, 08:56 AM  #1 
Subscriber
Join Date: Jul 2006
Location: London
Posts: 567

orbiting expression
Hey guys, I am just starting to get into Expressions, well object based expressions anyway, I have a bit of experience with particle expressions.
Anyways, I was wondering how I would make an object orbit another object, and how I would get it to maintain a constant distance if the object being orbited was moving. Any ideas would be much appreciated!! Chris 
Reply with quote 
17012008, 08:59 AM  #2 
Registered User
Join Date: Dec 2005
Location: Brooklyn, NY
Posts: 3,708

don't know anything about expressions, but if you move the pivot of the satelite to the center of the object being orbited, and then maybe parent it (i think) it would be fairly easy and just a case of setting keys.

Reply with quote 
17012008, 10:21 AM  #3 
Registered User
Join Date: May 2004
Location: UK
Posts: 1,991

as arran says, the easy way is to shift the pivot point and then simply rotate the orbiting object.
If you want to physically rotate it then a bit of maths is needed for figuring the location in space and moving it accordingly. I was playing about with papervision3D early last year and wrote a little flash script to rotate a moon around a planet in 3D space. If I can find it I'll post it up as an example that could be used as a 'principle of doing it' sample that could be modified for maya. As a final thought just have a good search for maya related versions as it might be fairly simple to get the effect working with dynamics. Good luck Simon
__________________
Examples of bTraffic  a traffic animation tool for Maya bFlocking  a tool for Maya 8.5+ to generate flocking and swarming behaviours Jan/Feb Challenge 2007 Entry and W.I.P May/Jun Challenge 2006 Entry and W.I.P Mar/Apr Challenge 2006 Entry and W.I.P Jan/Feb Challenge 2006 Entry and W.I.P Nov/Dec Challenge 2005 Entry and W.I.P Sep/Oct Challenge 2005 Entry and W.I.P Jul/Aug Challenge 2005 Entry www.flashfx.net 
Reply with quote 
17012008, 02:44 PM  #4 
Registered User
Join Date: May 2004
Location: UK
Posts: 1,991

Here you go  again its in actionscript but it shows the principles of using sin and cosine to figure out the position in 3D space and create an orbit. You might need to read around it a bit to get what you want. The main bit you'll be interested in is the loop3D function at the bottom:
Code:
class org.papervision3d.samples.orbit.orbit_test extends MovieClip { // _______________________________________________________________________ // vars3D var container :MovieClip; var scene :Scene3D; var camera :FreeCamera3D; var sphere :Ase; // _______________________________________________________________________ // Main function orbit_test() { init3D(); this.onEnterFrame = loop3D; } // _______________________________________________________________________ // Init3D function init3D() { // Create container movieclip and center it container = this.createEmptyMovieClip( "container", this.getNextHighestDepth() ); container._x = 320; container._y = 240; // Create scene scene = new Scene3D( container ); // Create camera camera = new FreeCamera3D(); // Create material var texture :BitmapData = BitmapData.loadBitmap( "Bitmap" ); var material :BitmapMaterial = new BitmapMaterial( texture ); material.oneSide = true; // Make it single sided // Load sphere sphere = new Ase( material, "world.ase", .1 ); sphere.rotationX = 0; sphere2 = new Ase( material, "world.ase", .025 ); sphere2.rotationX = 0; sphere2.rotationZ = 45; // set the moon to be 125 away from the planet sphere2.x = sphere.x + 125; sphere2.y = sphere.y + 125; sphere2.radians = 0.785 sphere2.degrees = 45; sphere3 = new Ase( material, "world.ase", .025 ); sphere3.x = sphere.x + 125; sphere3.y = sphere.y + 125; sphere3.z = sphere.y + 125; sphere3.radiansX = 2; sphere3.radiansY = 0; sphere3.radiansZ = 0; sphere4 = new Ase( material, "world.ase", .025 ); sphere4.x = sphere.x + 0; sphere4.y = sphere.y + 176; sphere4.radians = 0 sphere4.degrees = 0; // Include in scene scene.push( sphere ); //scene.push( sphere2 ); scene.push( sphere3 ); //scene.push( sphere4 ); } // _______________________________________________________________________ // Loop function loop3D() { // calculate the distance between the two (based on the origin being the planet at 0,0,0 dist = Math.sqrt((sphere2.x * sphere2.x) + (sphere2.y * sphere2.y)); _root.distance.text = dist; // calculate distance between two (z axis ball) distz = Math.sqrt((sphere3.x * sphere3.x) + (sphere3.y * sphere3.y)); angle = sphere2.radians; sx_pos = Math.sin(angle) * dist; sy_pos = Math.cos(angle) * dist; sphere2.x = sx_pos; sphere2.y = sy_pos; sphere2.radians += 0.01; sphere2.radians += 0.01; sphere2.radians += 0.01; // combined anglex = sphere3.radiansX; angley = sphere3.radiansY; anglez = sphere3.radiansZ; sx_pos = Math.sin(anglex) * dist; sy_pos = Math.cos(anglex) * dist; cx_pos = Math.sin(anglez) * dist cz_pos = Math.cos(anglez) * dist vy_pos = Math.sin(angley) * dist vz_pos = Math.cos(angley) * dist sphere3.x = sx_pos; sphere3.z = cz_pos; sphere3.y = vy_pos; sphere3.radiansX = 0.03; sphere3.radiansY += 0.03; sphere3.radiansZ += 0.03; sphere3.rotationY = sphere3.rotationY + 0.2; //sphere.rotationX = sphere.rotationX; //container._ymouse /3; sphere.rotationY = sphere.rotationY + 0.4; // Render scene.renderCamera( camera ); } function toRadians(degree:Number):Number { return degree / 180 * Math.PI; } function toDegrees(radian:Number):Number { return radian * 180 /Math.PI; } } http://www.flashfx.net/3D/masters/i...on3D/orbit.swf Simon
__________________
Examples of bTraffic  a traffic animation tool for Maya bFlocking  a tool for Maya 8.5+ to generate flocking and swarming behaviours Jan/Feb Challenge 2007 Entry and W.I.P May/Jun Challenge 2006 Entry and W.I.P Mar/Apr Challenge 2006 Entry and W.I.P Jan/Feb Challenge 2006 Entry and W.I.P Nov/Dec Challenge 2005 Entry and W.I.P Sep/Oct Challenge 2005 Entry and W.I.P Jul/Aug Challenge 2005 Entry www.flashfx.net Last edited by t1ck135; 17012008 at 02:49 PM. 
Reply with quote 
Reply 
Thread Tools  
Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Expression on Bend Deformer Problem  Calvin  Programming  0  22082016 08:24 AM 
:help: Problem with varying refractive index using Expression Editor  EonStrife  Lighting & Rendering  4  15122011 04:12 AM 
rotation expression troubles  bendingiscool  Programming  1  26102007 10:18 PM 
important question with expression editor  Jay_R_Locke  Maya Basics & Newbie Lounge  1  28112003 02:50 PM 
Need help troubleshooting expression.  NitroLiq  Programming  4  08012003 01:32 PM 
