Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Script: Object sends avatar into space

Peter Linden
Registered User
Join date: 18 Nov 2002
Posts: 177
04-14-2003 14:24
Object sends avatar into space

Summary: The following script will make an object that, once attached, will send you soaring into space. To use, create any single-primitive object, attach this script, then attach the object to your avatar.

Usage: if you jump when this is attached, you will go soaring through the air. Also, if you turn quickly, there is a chance that your foot will strike the ground, and, you guessed it, send you into space. What is it good for? Mainly the coolness factor of being able to jump 6,500 meters plus in a single bound. I rode it to 60k once, but got bored and teleported home at that point.

Script:
CODE

default
{
attach(key avatar)
{
vector force = <0,0, llGetMass() * 6.2>;
llSetForce(force, TRUE);
if(avatar==NULL_KEY)
{
llSetForce(<0,0,0>,TRUE);
}
}
}

Credits:
Script written by:
Nada Epoch 3-20-03
Zanlew Wu
Registered User
Join date: 5 Feb 2003
Posts: 112
04-26-2003 08:19
Hey Nada,

Why does this work? Is it constant? Does it ever stop? Do you slow down? Does friction or wind resistance affect this script? Why the check for Avatar==null? Would you mind commenting this one up a bit?
_____________________
In theory, practice and theory are the same thing. In practice, they're not.
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Re: Script: Object sends avatar into space
05-14-2003 05:56
this is from the scripting forum, but it belongs here so i reposted it.

me-
more comments :D First a simple physics lesson. The force on an object is equal to the objects mass multiplied by its current acceleration. So the equation is f=ma where f is force, m is mass, and a is acceleration. This script is totally and completely based off of this eqaution.

The only force that is always acting on the avatar is gravity, which is an acceleration of 9.8. the vector that represents this acceleration is <0,0,-9.8> because gravity is always pushing the avatar down. So the force that is caused by gravity, in vector form is <0,0,-9.8*Mass_of_Avatar>. So what this script does is, when attached to the avatar, icreate a force that is pointing in the positive z direction, that counter acts gravity. You can add the two vectors together to find out exactly how much gravity is still acting on you, since the force we are applying to the avatar is less than 9.8. The resultant(the force on the avatar) is <0,0,-3.6*Mass_of_Avatar>. This means that your avatar is basically working in 1/3 of the gravity that it is used to. Now the reason it sends you flying into space is because the avatar uses a certain amount of force to move around, and this force has been calculated given that gravity will be pushing down a certain amount on the avatar. Basically this script makes it like you are on the moon, your wieght is 1/3 (yeah, yeah i know gravity on the moon is 1/6) of what it is normally, but your muscles are still used to working at the full weight, so you can jump really really high!

ok so now to the code.

CODE

default
{
attach(key avatar) // this event is called everytime the object is
attached or unattached from an avatar.
{
vector force = <0,0, llGetMass() * 6.2>; //This first line
merely determines the desired vector that we will apply
to he avatar. I used the llGetMass() because at some
point attachments are going to start having weight, and we
will need to compensate for those in our equations.

llSetForce(force, TRUE);//This takes the force we determined
above, and applies it to the avatar. So the sum of the forces,
from gravity and the object, is <0,0,-3.6*Mass_of_Avatar>.
which means that the avatar is now working at 1/3 gravity.

if(avatar==NULL_KEY) //this is a safe guard. If you unattach
the obejct, it would fly off into the sunset because llSetForce()
is basically a permanent command. Meaning that the force
will still stay on the object, until you change the force. So
to prevent it from flying off, we have it chack to see if it is attached
and if it isn't it sets the force on the object to <0,0,0>.
{
llSetForce(<0,0,0>,TRUE);
}
}
}


From: someone
Originally posted by Zanlew Wu
Ok, so let me see if I understand this, based on what you said.

1) Presume Avatar A is standing still.

2) Current force G being applied by the world (server) is <0,0,-9.8> where -9.8 represents standard gravity.

3) Presume A attaches object O.

4) O has a script that performs the following steps:
a) create a vector to represent opposing force F (x,y,+Z). F, while a positive value, is smaller than G.
b) apply F to O. Since O is attached to A, F inherently gets applied to A.
c) O checks to see if it is attached to A or not. If detatched, stop applying F.

Now, in that example, since A is standing still, nothing happens. However, if A were to jump in place, additional movement will occur that is not experienced under normal gravity.

If I understand what I am reading, since G is still greater than F (though G is negative and F is positive, making them opposing forces) the greater G will still result in bringing A back down to terra firma eventually. If F were to be greater than G, user would never come back down. Am I getting it so far?

Ok, so if I understand what I am reading, my remaining questions are:

1) Why select 6.2? Is something magic about that value? Isn't 2/3rds of 9.8 equal to 6.5333333333 or 6.6 or something? Or was the selection of 6.2 intentional?

2) Would one ever want to llSetForce(force, FALSE)? What effect would that have? The script ref is not very clear on this. Not sure what that means. You didn't mention anything about O needing to be physical or not that I can recall.

3) In your comments on that same line (llSetForce), wouldn't the sum of forces be (-9.8) - 6.2 = 3.6? And wouldn't 1/3 of 9.8 be 3.266666667? I know this is just a comment, but I just want to make sure I understand and am not missing something terribly obvious to the rest of the world (would not be the first time!)

Thanx for the clear understanding though, Nada...as well as the physics lesson! It is most helpful and useful!


me
First, the acceleration due to gravity is <0,0,-9.8>, but the force caused by gravity is totally dependant on the mass of the object.

so your summary is spot on.

so for your questions:

1) 6.2 is a semi arbitrary number. 0 gravity(i.e. if we set the force 9.8) is nearly impossible to control because the net force acting on you is 0, so a force that is applied to you whether it is by another avatar or just you walking causes you to travel in the direction you were pushed, ad infinitum. There is no air resistance, but there is a max speed.

2) yes you would. That flag determines what axis to push the force along. If it is set to true as in this case, it aligns the force with the local axis of the object. So if the avatar was upside down, the force would be pushing heading towards the ground because the local z axis of the avatar would be pointing down. If it is set to false, then it aligns the force with the world coordinates, so no matter the orientation of the avatar, the force would always be pointing straight up, along the z axis. So now you might ask, why i didn;t set it to false, and i would tell you it is because i am trixy . The actual reason is that it is out of habit, and luckily it doesn't cause a problem because avatar z axis only changes minorly, unless you do sitting object tricks.

3) math error, and you have one too (-9.8) - 6.2 = -17, geeze everyone is a critic haha

the last issue brought up is the physicallity of the object that has the script on it. if it were not going to be attached to an avatar, then yes, you would need to make it physcial. but when you attach it to your avatar, well your avatar is automatically physical, so it isn't necessary.
_____________________
i've got nothing. ;)
Lecktor Hannibal
YOUR MOM
Join date: 1 Jul 2004
Posts: 6,734
07-21-2004 08:38
Could this be used for solo skydiving or does it place your av in a "fly" mode ?
Thanks,
Lecktor
_____________________
YOUR MOM says, 'Come visit us at SC MKII http://secondcitizen.net '

From: Khamon Fate
Oh, Lecktor, you're terrible.

Bikers have more fun than people !
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
07-21-2004 09:03
hmm i don't know anything about sky diving in its current form, so i cannot answer that question. However the script doesn't put your avatar into fly mode, it just lightens your load so to speak. Basically this script makes it like your avatar is on the moon, working in 1/3 the gravity.

heh or is gravity on the moon 1/6th?
_____________________
i've got nothing. ;)
Lecktor Hannibal
YOUR MOM
Join date: 1 Jul 2004
Posts: 6,734
07-21-2004 09:18
hmmm, forgive my obvious noobness. I know nothing about LSL yet but am trying to learn. I understand the mass decreasing. Is there a way to put an altitude setting or say a timer / kill function where your mass returns normal and a freefall condition begins ?
Thanks again,
Lecktor
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
07-21-2004 11:40
ah, this is probably not the script you want. A couple a things that you could do though.
  1. you could just apply an impulse to yourself and manually kill it with your fly button at the desired height.
  2. again with the impulse you could have a timer checking your height and once you are a certain point you could call a llMoveToTarget to kill your speed.
  3. still with the impulse, you could call the impulse and then have the script apply a force on you that would gradually slow you down, then you have a timer even checking to see if your velocity is negative in the z, and once it is, then it terminates the force.
  4. or use the target and not_at_target event to propel yourself forward probably using either the llMoveToTarget or llSetHoverHeight calls.

i will script them all up tonight, and post them to the library, if someone doesn't do it before i get out of work :).
_____________________
i've got nothing. ;)
Lecktor Hannibal
YOUR MOM
Join date: 1 Jul 2004
Posts: 6,734
07-21-2004 12:09
Thanks for the reply Nada very detailed and informative. I don't know if those calls will work tho. The skydiving parachutes require a non - flying state. i.e. freefall. Cubey's vehicle is awesome but the pilot can't jump per se and leave the vehicle at meters unatainable by av fly. His elevator is awesome too, but I woul d like a script so I can propel myself up say 2k-4k m and then freefall. My original question was diggin for brainstorms actually to try and learn how to adapt this script possibly but feel free to script it for us LOL:D
Thanks again I can't get over all of the helpfulness in my 2 weeks or so of SL.
Lecktor
RacerX Gullwing
Magic Rabbit
Join date: 18 Jun 2004
Posts: 371
10-04-2004 17:18
I played with this for a while put it in an arm band, I couldn't get it boost me very high just about two stories maybe when I jumped. Tried turning on jump, on landing couldn't do the massive high though.
But then at the end of a show and tell event someone was jumping pretty high so I put my arm band on and stood up and swoosh I was at unknown number of feet up. So I put my parachut on and opend it. Couldn't tell if I was going up or down. Till I put a an instruments script in my cane that showed altitude and then I could see I was still climbing.
so I repackaged my parachute and altitude was still going up. I was at about 3000 when I decided to take the armband off. Then the numbers slowed down till I was going down finally at about 3500.M Well I waited till I was about 700 meters left and pulled my chute but it said I had already used it. Then I went smak-o right at the exact spot I'd stood up from. A few minutes earlier.
Hiro Pendragon
bye bye f0rums!
Join date: 22 Jan 2004
Posts: 5,905
10-12-2004 03:03
OOH! OOH!

I think I need to put this script in a cookie, and leave them copyable / transferrable around SL! *evil grin*
_____________________
Hiro Pendragon
------------------
http://www.involve3d.com - Involve - Metaverse / Emerging Media Studio

Visit my SL blog: http://secondtense.blogspot.com
Gunther Baggio
Registered User
Join date: 14 May 2004
Posts: 4
It wont work!
10-14-2004 07:44
I have been trying to get this to work but it wont so if it is working for anyone else can they plz post it?
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
10-17-2004 12:15
well it would appear that whatever physics bug that was allowning this has been fixed. That being said, this script and any script like it basically just adjusts the effect of gravity on you, so with the current force it is like being on the moon. If you like that Idea(of adjusting gravity on your avatar) then you may actually want to use the llSetBuoyancy(float buoyancy) command.

so in our script:
CODE

default
{
attach(key avatar)
{
llSetBuoyancy (0.6);
if(avatar==NULL_KEY)
{
llSetBuoyancy (0.0);
}
}
}

If you want to get sent up in the air, then i suggest looking at the sky diver script
_____________________
i've got nothing. ;)