Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

object rotation based on movement direction and speed

lissa Denja
Registered User
Join date: 23 Dec 2007
Posts: 1
04-24-2008 02:43
hello,

I am changing this slightly, to see if this will help on getting a response.
i am using the balloon tour script from a book I am studying and have attached it

could someone please tell me what i need to do to get the darn thing to turn to face the direction of travel?

i have looked at a vehicle script, but am not sure how to combine the two.
Ellain Gausman
Registered User
Join date: 19 Aug 2007
Posts: 1
turn to face the direction of travel
08-27-2008 07:08
I am very new to scripting .. but i was playing with the same Balloon tour script you have.
i found an easy way to get it to face the direction of travel was to use the
llLookAt(target, 1, .5); command.
You only need to becareful to place the script in an object linked to the balloon that can be rotated propery so the whole balloon does not tilt in the direction you are traveling.

// From the book:
//
// Introduction to Linden Scripting Language for Second Life
// by Jeff Heaton (Encog Dod in SL)
// ISBN: 1604390042
// Copyright 2007 by Heaton Research, Inc.
//
// This script may be freely copied and modified so long as this header
// remains unmodified.
//
// For more information about this book visit the following web site:
//
// http://www.heatonresearch.com/articles/series/24/

float dir;

float SPEED = 1;
vector target; // 182.461.70.566,21.079
list waypoints;
integer currentWaypoint;
string message;

// for loading notecard
string notecardName = "Configure balloon";
key notecardQuery;
integer notecardIndex;


integer nextWayPoint()
{
if( currentWaypoint>= llGetListLength(waypoints) )
{
llSay(0,"Ride over";);
return TRUE;
}
else
{
target = llList2Vector(waypoints,currentWaypoint);
message = llList2String(waypoints,currentWaypoint+1);
currentWaypoint+=2;
llLookAt(target, 1, .5);
return FALSE;
}

}


default
{
state_entry()
{
llSay(0,"Touring balloon loading waypoints...";);
notecardIndex = 0;
notecardQuery = llGetNotecardLine(notecardName,notecardIndex++);
}

dataserver(key query_id, string data)
{
if ( notecardQuery == query_id)
{
// this is a line of our notecard
if (data == EOF)
{
llSay(0,"Data loaded, touring balloon ready...";);
state waiting;

} else
{

list temp = llCSV2List(data);

vector vec = (vector)llList2String(temp,0);
string str = llList2String(temp,1);
waypoints+=[vec,str];
notecardQuery = llGetNotecardLine(notecardName,notecardIndex++);
}
}
}
}




state running
{



state_entry()
{

currentWaypoint = 0;
llSitTarget(<0,-0.5,0.5>, llEuler2Rot(<0,0,-90>;) );
llSetText("",<255,0,0>,1.0);
nextWayPoint();
llSetTimerEvent(0.1);
}

timer()
{
vector pos = llGetPos();
integer match = 0;

if( llFabs(pos.x - target.x) < SPEED )
{
pos.x = target.x;
match++;
}
else
{
if( pos.x > target.x )
pos.x-=SPEED;
else
pos.x+=SPEED;
}

if( llFabs(pos.y - target.y) < SPEED )
{
pos.y = target.y;
match++;
}
else
{
if( pos.y > target.y )
pos.y-=SPEED;
else
pos.y+=SPEED;
}

if( llFabs(pos.z - target.z) < SPEED )
{
pos.z = target.z;
match++;
}
else
{
if( pos.z > target.z )
pos.z-=SPEED;
else
pos.z+=SPEED;
}

llSetPos(pos);

if( match==3 )
{
string hold = message;
if( nextWayPoint() )
state waiting;
llSay(0,hold);
}




}

}

state waiting
{
state_entry()
{
llSay(0,"Touring balloon is waiting.";);
}

link_message(integer sender_num, integer num, string str, key id)
{
if( str=="go" )
{
state countdown;
}
}
}

state countdown
{
state_entry()
{
llSetTimerEvent(20);
llSay(0,"Welcome to the touring balloon ride. The balloon will take flight in 20 seconds. Please take your seats!";);
}

timer()
{
state running;
}
}
Jim Perhaps
Registered User
Join date: 10 Dec 2005
Posts: 65
Notecard data structure
09-24-2008 10:24
I am curious what data structure is for the notecard

coma delimiter or semicolon or what?

can someone post an an example please?
Champie Jack
Registered User
Join date: 6 Dec 2003
Posts: 1,156
09-24-2008 10:57
From: Jim Perhaps
I am curious what data structure is for the notecard

coma delimiter or semicolon or what?

can someone post an an example please?


In this example the dataserver event reads the ONE notecard line at a time as a string with COMMAS separating the values. If you look at the script, the notecard line is converted to a LIST using llCSV2List():
CODE
                 list temp = llCSV2List(data);

http://lslwiki.net/lslwiki/wakka.php?wakka=llCSV2List

example:
CODE

Sea Serpents,Phobos,193,164,50,80,0,15
The University of Second Life,Phobos,68,216,80,0,15
The Phobos Project,Phobos,159.05653,57.19658,39.69685,80,0,15


These were taken from Hank Ramos Hot Air Touring Balloon.
Jim Perhaps
Registered User
Join date: 10 Dec 2005
Posts: 65
Thank you
09-25-2008 07:41
Champie,

Thank you for your response! :)