Maya 2020 fundamentals - modelling the real world
Get halfway through a model and find it's an unworkable mess? Can't add edge loops where you need them? Can't subdivide a mesh properly? If any of this sounds familiar check this course out.
# 1 17-01-2008 , 08:56 AM
bendingiscool's Avatar
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

# 2 17-01-2008 , 08:59 AM
arran's Avatar
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.

# 3 17-01-2008 , 10:21 AM
t1ck135's Avatar
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 user added image
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.flash-fx.net
# 4 17-01-2008 , 02:44 PM
t1ck135's Avatar
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;
	}
}
and an example of 2 moons orbiting around a planet (in 3D in flash) - although the camera angle makes it look 2D. Minimise the page to make it run faster:
https://www.flash-fx.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.flash-fx.net

Last edited by t1ck135; 17-01-2008 at 02:49 PM.
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads