Object automatically fly arround another Object
|
Cypher Black
Registered User
Join date: 14 Apr 2005
Posts: 15
|
06-03-2005 12:37
Hi Folks
has anyone an idea how to make a object flying around another one ? The idea is to having flying pet's, and they should fly randomly arround my home. Would also be more then nice if it would be possible to enter the distance (how far this pet's can move away from my house)
I have no idea how to do it ; perhaps someone could post me help, or even better an example script.
Thanx a lot and always remeber HAVE FUN !
|
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
|
06-03-2005 15:54
_____________________
---
|
Zindorf Yossarian
Master of Disaster
Join date: 9 Mar 2004
Posts: 160
|
06-03-2005 17:14
I don't think that's really what Cypher was getting at...
_____________________
Badass Ninja Penguin: Killing stuff it doesn't like since sometime in May 2004.
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
06-03-2005 17:44
There are a lot of ways to do it. One way would be to use an on_rez() event or similar (listen, touch etc.) so you can set home. Each time it arrives you choose a random target position for it to fly to, do llVecMag() to check it's within the right distance. You could do something fancier, limit the randomiser to home ± the maximum distance on each of the vectors say, that will give you the very limits of the sphere and give you fewer false locations to force a recheck. You could also do smaller moves, and check each of them depending on what you're trying to mimic.
|
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
|
06-03-2005 18:49
From: Zindorf Yossarian I don't think that's really what Cypher was getting at... "Flying pets" leads me to post that as a place to start. The only major difference will be in the constant used for the sensor, and any additional movement code. For that, one can check the Wiki: http://secondlife.com/badgeo/wakka.php?wakka=llSensor
_____________________
---
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
06-04-2005 02:39
Why use a sensor for flying around a house?
I have yet to see a walking, moving house in SL, although that does give me an idea...
Sensors are vital for pets flying around you, or anything else that moves, but if your house stays still you can get away with taking the position of the house and a simple vector magnitude to define the distance it can stray. Saves on the lag too, no pinging around the sim that way.
|
Cypher Black
Registered User
Join date: 14 Apr 2005
Posts: 15
|
Hi Again
06-04-2005 09:58
Thanx a lot for your posts here, *but* I am a real newbie in scripting ! The idea is to have a little "watchdog" who is telling me what is going on arround my house. I think the idea with the "simple vector magnitude to define the distance it can stray" is the best one. Has anyone allready an example script for this ? btw : Legith Fairplay has done something with his Butterfly's (can be found here : http://www.slexchange.com/modules.php?name=Marketplace&file=item&ItemID=11458 ) Thanx a lot for all your help, and HAVE FUN !
|
Legith Fairplay
SL Scripter
Join date: 14 Jul 2004
Posts: 189
|
06-04-2005 11:14
The butterflies have a random move script that sets the distance to travel on an axis between 0 and a maximum distance per movement tick (2 seconds I believe) and makes sure this movement is within a bounding cube.. if not recalculate. This idea can be made into a 2d box by not updating the z axis, or a circle by checking the radius of the new location from the central location. (as opposed to my cube defined by offsets from the center point). If you want the script custom to your house you can even check the cut out to allow the guard dog to move around the property and not only part of your "front yard" The following example should move an object randomly within a circle on the x,y plane: float radius = 5.0; //distance from starting point to wonder float timeout = 2.0; //time between movement changes float max_dist = 3.0; //max distance to move on x/y axis per timeout
vector start; //starting location, found on start/rez
//randomly move somewhere within the defined circle random_move(){ vector pos; //new position float dist; //distance from center //calculate the new position do{ //start with the current position pos = llGetPos(); //randomly update x/y cords pos.x += llFrand(max_dist * 2)-max_dist; pos.y += llFrand(max_dist * 2)-max_dist; //calculate dist = sqrt( diff(x)^2 + diff(y)^2 ) dist = ((pos.x - start.x) * (pos.x - start.x)) + ((pos.y - start.y) * (pos.y - start.y)); dist = llSqrt(dist); //if we are outside of the circles radius try again }while(dist > radius);
//move to the new point llMoveToTarget(pos,timeout); }
default{ state_entry(){ //get starting point and init timer start = llGetPos(); llSetTimerEvent(timeout); //move the object random_move(); } on_rez(integer i){ //get starting point and init timer start = llGetPos(); llSetTimerEvent(timeout); //move the object random_move(); } timer(){ //move the object random_move(); } }
Note: the above code was not tested and coded here not in world.. so there may be errors. Also its a good idea for objects like this to be phantom unless otherwise required. Hope this is a good starting point.
|
Cypher Black
Registered User
Join date: 14 Apr 2005
Posts: 15
|
Thanx a lot for your help (but)
06-08-2005 11:43
Hi Legith Thanx a lot for your help ! I have tryed out the script and made a little change, i think there was a littlte typo in it, but i am not sure...(scripting newbie  on the line : on_rez(int i){ ....... i made the change : on_rez(integer i){..... *BUT* I am not sure if this is right  anyway, now i can compile it without error. I attached the script on a object, but the problem is the object is not moving arround. Am I'm doing something wrong ? Thanx a lot and HAVE FUN !
|
Legith Fairplay
SL Scripter
Join date: 14 Jul 2004
Posts: 189
|
06-08-2005 12:07
From: Cypher Black on the line : on_rez(int i){ .......
i made the change : on_rez(integer i){.....
.. fixed above (the problem with working in many similar languages) From: Cypher Black I attached the script on a object, but the problem is the object is not moving arround.
make sure the object is physical, as non physical objects won't move with physics calls. (useful if you want something to stop and stay still for a while is to make it non-physical)
|