Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Vectors to velocity

Leffe Nyak
Registered User
Join date: 24 Jan 2005
Posts: 3
02-05-2005 02:36
im having some difficulties making a certian phrase in my script work just right...
and i am currently getting a syntax error between pox and .x in the first phrase
im trying to say:

vector pos.x = llGetVel;

V
O
I rest of a vehicle script
D

if(level & CONTROL_FWD)
{
gLinearMotor = (pos.x + <10,0,0>;);
if ( pos.x > (<0,0,0>;) && pos.x < (<15,0,0>;)) {pos.x =10;}

if ( pos.x > (<16,0,0>;) && pos.x < (<25,0,0>;)) {pos.x =20;}

if ( pos.x > (<26,0,0>;) && pos.x < (<35,0,0>;)) {pos.x =30;}

if ( pos.x > (<36,0,0>;) && pos.x < (<45,0,0>;)) {pos.x =40;}

if ( pos.x > (<46,0,0>;) && pos.x < (<55,0,0>;)) {pos.x =50;}

key_control = TRUE;
}
if(level & CONTROL_BACK)

the point is to have the control set so that whenyou hti forward you move forward on the x axis at a constant velocity of 10, which increases each time you hit forward, im pretty new at scripting... and am geting bogged down tryign to get this to work. any suggestions?
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
02-05-2005 02:54
thats because llGetVel returns a global vector.

http://secondlife.com/badgeo/wakka.php?wakka=llGetVel
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Jimmy Loveless
Hello, avatar!
Join date: 1 Oct 2004
Posts: 35
02-05-2005 02:56
I don't know much about getting the rest of your script going but that first line of code is getting a syntax error for a couple reasons:

vector pos.x = llGetVel;

1. you can't operate on the .x .y or .z of a vector til you declare it:

vector pos;
pos.x = ...something...

2. llGetVel() needs an empty set of parenthesis after it for it to work:

vector velocity = llGetVel();

Now that that is fixed... llGetVel() returns a vector, which will cause a type mismatch error, because pos.x wants a float data type. you might find the wiki helpful if you haven't checked it out.

Cheers,
JL
Leffe Nyak
Registered User
Join date: 24 Jan 2005
Posts: 3
02-05-2005 03:07
ive checked out the wiki and done a good many of things ive tried out what you two have stated and i still seem to be lacking something
Vortex Saito
Quintzee Creator
Join date: 10 Sep 2004
Posts: 73
02-05-2005 03:46
Perhaps I am looking all wrong at this script, but

If pos.x is a vector, shouldn't the line read :

if ( pos.x > (<0,0,0>;) && pos.x < (<15,0,0>;)) {pos.x =<10,0,0>;} ???

Because pos.x is a vector.
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
02-05-2005 06:10
From: Vortex Saito
Perhaps I am looking all wrong at this script, but

If pos.x is a vector, shouldn't the line read :

if ( pos.x > (<0,0,0>;) && pos.x < (<15,0,0>;)) {pos.x =<10,0,0>;} ???

Because pos.x is a vector.


pos.x is a float, pos is a vector.
==Chris
Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
02-05-2005 06:21
Yup, a vector is simply a set of three floats.
If you want to have slightly structured data, you can use vectors and rots as raw storage.
It comes in handy sometimes.
Rhombur Volos
King of Scripture & Kebab
Join date: 6 Oct 2004
Posts: 102
02-05-2005 09:28
CODE


//put this part in global variable declaration
vector movement = ZERO_VECTOR;


if(level & CONTROL_FWD)
{
movement.x += 10;
// key_control = TRUE;
// since the control event is only started if a control key is pressed,
// this variable isn't really neccesary.
}



You might also want to make a piece of code that makes the vehicle decelerate faster at high speeds.
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
02-05-2005 09:38
As for getting it to, ehm... do what you want.

CODE
vector forward = llGetRot() / <10,0,0>; //Returns forward on your X axis
vector current_vel = llGetVel(); //Returns current velocity vector

//Now, to get how fast we're going on X, we split up the vector

//Example

if(current_vel.x > forward.x && current_vel.y > forward.y && current_vel.z > forward.z)
//If all this checks out, we must be going faster than 10m on the X-axis.
llSay(0,"Moving faster than 10m");

//Alternately, you can then multiply your forward vector to get speeds equivalent to 20m, 30m, 55m, etc.
//However, one thing I prefer using is llVecMag, to cut off total velocity at a given number
//See here: http://secondlife.com/badgeo/wakka.php?wakka=llVecMag

I find, though, that a total velocity constant is more effective than simply one that works on a single axis, but it's your call.

Also:
From: Jimmy Loveless
1. you can't operate on the .x .y or .z of a vector til you declare it:

vector pos;
pos.x = ...something...

Incorrect. pos.x, pos.y, and pos.z would all have been declared the moment you declare a vector. You can also set a vector to an initial value directly via vector pos = <0,0,0>;

From: Rhombur Volos
CODE


//put this part in global variable declaration
vector movement = ZERO_VECTOR;


if(level & CONTROL_FWD)
{
movement.x += 10;
// key_control = TRUE;
// since the control event is only started if a control key is pressed,
// this variable isn't really neccesary.
}



You might also want to make a piece of code that makes the vehicle decelerate faster at high speeds.

Unfortunately, this won't do a thing unless you have a vehicle motor set. If Leffe is using vehicle code, that might be different.
_____________________
---
Leffe Nyak
Registered User
Join date: 24 Jan 2005
Posts: 3
02-05-2005 13:45
well... i got it working with the help of jimmy loveless he spent a great deal of time looking overe every thing i apreciate the help.