Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Orbit Script

Perre Anatine
reflect..repent..reboot
Join date: 6 Jun 2007
Posts: 714
01-28-2008 20:46
I wondered if anyone has come across a script that will allow one object to orbit another over a large distance. I'm currently building the Solar System and have managed to get the planets orbiting the sun, each linked by a set of transparent prims and a rotating prim located at the centre of the sun. Each planet is linked to it's own rotating prim so that way I can vary the rate of rotation of each. I've even managed to get the planets rotating about their own axis and to include moons orbiting the planets.

My main problem though is..it's just not big enough. At the moment I'm limited to a maximum of a 40 (ish) metre radius. I want to go sim wide and have a maximum radius of 128 metres, with the sun located right at the centre of the sim.

So I thought there might be a script out there that would allow me to set my planets in motion moving along a circular path about a central point (rather than the linked prim method)..anyone seen such a thing..?

Thanks..Perre.. :D
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
01-28-2008 23:27
You will want to look into llSin() and llCos()
Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
01-29-2008 03:13
CODE

rotate()
{
vector vVecOffset = <5.0, .0, 0.0>; //-- the point we are rotating around in relation to our object
vector vgVecArc = <.0, .0, 0.5>; //-- how far around the circle to travel each move
rotation vgRotArc = llEuler2Rot( vgVecArc * DEG_TO_RAD );
//-- notice you have to move AND rotate, or else the new
//-- position becomes a diagonal line instead of a circle
llSetPrimitiveParams( [PRIM_POSITION, llGetPos() + (vVecOffset - vVecOffset * vgRotArc) * llGetLocalRot(),
PRIM_ROTATION, vgRotArc * llGetLocalRot()] );

}

default
{
state_entry()
{
llSetTimerEvent(0.04);
}
timer()
{

rotate();
}
}


This is an adaptation code snippet I picked up on the forums. I think Void Singer is the original author so thanks need to be sent elsewhere (couldn't find the original thread) :)


Found it

/54/f2/221068/1.html
_____________________
Tread softly upon the Earth for you walk on my face.
Ilobmirt Tenk
Registered User
Join date: 4 Jun 2007
Posts: 135
01-29-2008 04:13
hehe, looks like others have done it before I have. Title should have been "Orbiting planets script" X3
Perre Anatine
reflect..repent..reboot
Join date: 6 Jun 2007
Posts: 714
01-29-2008 17:22
Thanks for the replies folks..

I'll give that one a try Django..thanks!!

Perre..:D
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-30-2008 15:05
over a large distance....

this formula will move a root object around an arbitrary offset

llSetPos( llGetPos() + (offset - offset * arc2travel) * llGetRot();
llSetRot( arc2travel * llGetRot() );

offset = the distance and direction in local axis to the point to rotate around, as a vector

arc2travel = the number of degrees, to travel in the circle around the offset, expressed as a rotation.

how it works:
+ offset moves us in to the center of our circle,
- offset * arc moves us around the circle and back out to it's edge
*llGetRot() translates the point based on the current facing of the objects
added to the current position, tells us where we should be going

then we have to rotate to keep facing our center

just be sure that if the calculation for llSetPos is greater than 10m it will fail unless fed to a function like warppos, or something that breaks it down to 10m or less increments.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Anti Destiny
Registered User
Join date: 4 Jan 2008
Posts: 2
Orbit
01-30-2008 18:00
From: Ilobmirt Tenk
hehe, looks like others have done it before I have. Title should have been "Orbiting planets script" X3


Heh, from the post title I thought you meant the overly annoying stratospheric push script.

Do you have a viewable demo of the solar system setup anywhere inworld? I'd love to see it. =^.^=

Void's new formula looks awesome, I'm just guessing at this point but I bet it's alot smoother than the first example.

I might be missing something but I don't see a way to control the speed of revolution, any tips Void? Am I overlooking the obvious?
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-31-2008 01:05
From: Anti Destiny
Heh, from the post title I thought you meant the overly annoying stratospheric push script.

Do you have a viewable demo of the solar system setup anywhere inworld? I'd love to see it. =^.^=

Void's new formula looks awesome, I'm just guessing at this point but I bet it's alot smoother than the first example.

I might be missing something but I don't see a way to control the speed of revolution, any tips Void? Am I overlooking the obvious?

well first, it's a move so not a smooth rotation, 2nd the first script is the same as my script (in fact it's a conversion of one of mine, I'm flattered)... the speed would be controlled by timer or loop (as in the first example) I mostly posted to give the reasoning behind how it works.

smaller arc and timer increments will make it the smoothest possible, to set it to a particular speed the formula is time / (360 / arc), where time is how long it should take to make 1 full circuit..... just be aware that each move takes a set time to calculate, so if your required time is less than that it's going to run slow.

and don't forget the warning about >10m moves.

maximum arc per move should be (roughly) something like
360 / (offsetDistance * 2pi / 10).
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -