Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

NonPhy movement v3, with mouselook steering

Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
01-31-2006 14:21
Here are the movement scripts I use in the Pelican. Follow the instructions closely to use in your own builds ;)

The variable "hidden_face" must be the same for all the scripts, it's the face number that will be used to transmit information from the main script to the parralelle movement scripts, so make sure the face is not visible (5 is the inside face of hollowed cubes, on spheres it's 1).

These scripts are provided as-is. They work for me, and I can provide a ready-to-drop copy of those scripts inworld. You can use these scripts in a commercial build, but please keep them full perms if you do. This won't affect the permissions on your object in any way.

Move script: copy 4 times (call them move, move1, move2 and move3).
CODE

integer hidden_face = 5;

float max_vel;
vector veloff = <-0.5, -0.5, -0.5>;

default
{
link_message(integer part, integer code, string msg, key id)
{
if (msg != "nonphy") return;
max_vel = (float)((string)id);
llSleep(0.05 * (integer)llGetSubString(llGetScriptName(), -1, -1));

while(TRUE)
{
llSetPos(max_vel * (llGetColor(hidden_face) + veloff) + llGetPos());
llSetPos(max_vel * (llGetColor(hidden_face) + veloff) + llGetPos());
llSetPos(max_vel * (llGetColor(hidden_face) + veloff) + llGetPos());
llSetPos(max_vel * (llGetColor(hidden_face) + veloff) + llGetPos());
llSetPos(max_vel * (llGetColor(hidden_face) + veloff) + llGetPos());
}
}
}


Rota script: copy 4 times (call them rota, rota1, rota2 and rota3).
CODE

integer hidden_face = 5;
float max_vel;

default
{
link_message(integer part, integer code, string msg, key id)
{
if (msg != "nonphy") return;
max_vel = (float)code * DEG_TO_RAD;
llSleep(0.05 * (integer)llGetSubString(llGetScriptName(), -1, -1));
while(TRUE)
{
llSetRot(llGetRot() * llEuler2Rot(<0,0,max_vel * (llGetAlpha(hidden_face) - 0.5)>) );
llSetRot(llGetRot() * llEuler2Rot(<0,0,max_vel * (llGetAlpha(hidden_face) - 0.5)>) );
llSetRot(llGetRot() * llEuler2Rot(<0,0,max_vel * (llGetAlpha(hidden_face) - 0.5)>) );
llSetRot(llGetRot() * llEuler2Rot(<0,0,max_vel * (llGetAlpha(hidden_face) - 0.5)>) );
llSetRot(llGetRot() * llEuler2Rot(<0,0,max_vel * (llGetAlpha(hidden_face) - 0.5)>) );
}
}
}


Turn script: copy 4 times (call them turn, turn1, turn2 and turn3).
CODE

default
{
link_message(integer part, integer code, string msg, key id)
{
if (msg == "piloted")
{
if (id != "")
{
llRequestPermissions(id, PERMISSION_TRACK_CAMERA);
}
}
}

run_time_permissions(integer p)
{
if (p & PERMISSION_TRACK_CAMERA)
{
vector aim;
rotation ro;
key id = llGetPermissionsKey();
vector cor = ZERO_VECTOR;
llSleep(0.05 * (integer)llGetSubString(llGetScriptName(), -1, -1));
while(TRUE)
{
if (llGetAgentInfo(id) & AGENT_MOUSELOOK)
{
aim = llRot2Fwd(llGetCameraRot());
cor = aim;
aim.z = 0.0;
ro = llRotBetween(<1, 0, 0>, aim) * llRotBetween(aim, cor);
llSetRot(ro);
} else llSleep(0.2);
}
}
}
}


Main script: you may want to tweak a bit the initial speed and acceleration settings, and also the sit target and camera offsets.
CODE

// Non-Physical Flying Vehicle
// A.K.A: How to exploit tricks in LSL to get your way
//
// (your way being: up to 254 prims on a vehicle, in this case)
// Author: Jesrad Seraph
// Modify and redistribute freely, as long as your permit free modification and redistribution

integer hidden_face = 5;

float max_fwd = 2.0; // max speed in m per quarter of a second
integer max_rot = 4; // max turning speed in degrees per quarter of a second
float hover_height = 0.25; // prefered minimum height above ground

integer down;
integer change;

float fwd_accel = 0.015625; // forward/back acceleration
float up_accel = 0.015625; // vertical acceleration
float left_accel = 0.015625; // strafing acceleration
float rot_accel = 0.03125; // turning acceleration

float inertia = 0.75; // movement slowdown rate
float moment = 0.5; // turning slowdown rate


// internal stuff, don't modify
vector velocity;
float rotacity;
vector veloff = <0.5, 0.5, 0.5>;
integer timeout;

integer controls;
key pilot;

stop()
{
vector aim;
llReleaseControls();
llResetOtherScript("turn");
llResetOtherScript("turn1");
llResetOtherScript("turn2");
llResetOtherScript("turn3");
llResetOtherScript("rota");
llResetOtherScript("rota1");
llResetOtherScript("rota2");
llResetOtherScript("rota3");
llResetOtherScript("move");
llResetOtherScript("move1");
llResetOtherScript("move2");
llResetOtherScript("move3");
timeout = 0;
llSetTimerEvent(0.0);
pilot = NULL_KEY;
velocity = ZERO_VECTOR;
rotacity = 0.0;
llSetColor(velocity + veloff, hidden_face);
llSetAlpha(rotacity + 0.5, hidden_face);
aim = llRot2Euler(llGetRot());
aim.x = 0.0;
aim.y = 0.0;
llSetRot(llEuler2Rot(aim));
}

default
{
state_entry()
{
controls = CONTROL_FWD|CONTROL_BACK|CONTROL_UP|CONTROL_DOWN|CONTROL_LEFT|CONTROL_RIGHT|CONTROL_ROT_LEFT|CONTROL_ROT_RIGHT;
stop();
llSitTarget(<0.25, 0.0, 0.4>, ZERO_ROTATION);
llSetCameraAtOffset(<1.0, 0.0, 0.0>);
llSetCameraEyeOffset(<-3.0, 0.0, 0.0>);
}

on_rez(integer param)
{
llResetScript();
}

touch_start(integer c)
{
if (llDetectedKey(0) != llGetOwner()) return;
if (pilot == llGetOwner())
{
stop();
} else
{
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
}
}

run_time_permissions(integer p)
{
if (p & PERMISSION_TAKE_CONTROLS)
{
llResetOtherScript("turn");
llResetOtherScript("turn1");
llResetOtherScript("turn2");
llResetOtherScript("turn3");
pilot = llGetPermissionsKey();
llTakeControls(controls, TRUE, FALSE);
velocity = ZERO_VECTOR;
rotacity = 0.0;
llSetColor(velocity + veloff, hidden_face);
llSetAlpha(rotacity + 0.5, hidden_face);
llMessageLinked(LINK_THIS, 0, "piloted", pilot);
} else if (llGetPermissions() & PERMISSION_TAKE_CONTROLS == FALSE)
{
stop();
}
}

control(key id, integer level, integer edge)
{
down = level;
change = edge;

if (down & controls)
{
if (timeout == 0)
{
llMessageLinked(LINK_THIS, max_rot, "nonphy", (key)((string)max_fwd));
llSetTimerEvent(0.05);
}
timeout = 12;
}
}

timer()
{
if (--timeout == 0)
{
llResetOtherScript("move");
llResetOtherScript("move1");
llResetOtherScript("move2");
llResetOtherScript("move3");
llResetOtherScript("rota");
llResetOtherScript("rota1");
llResetOtherScript("rota2");
llResetOtherScript("rota3");
llSetTimerEvent(0.0);
return;
}

if (down & CONTROL_FWD)
{
if (velocity.x < 0.0) velocity.x = 0.0;
velocity.x += fwd_accel;
if (velocity.x > 0.5 ) velocity.x = 0.5;
} else if (down & CONTROL_BACK)
{
if (velocity.x > 0.0) velocity.x = 0.0;
velocity.x -= fwd_accel;
if (velocity.x < -0.5 ) velocity.x = -0.5;
} else {
velocity.x *= inertia;
}

if (down & CONTROL_UP)
{
if (velocity.z < 0.0) velocity.z = 0.0;
velocity.z += up_accel;
if (velocity.z > 0.5 ) velocity.z = 0.5;
} else if (down & CONTROL_DOWN)
{
if (velocity.z > 0.0) velocity.z = 0.0;
velocity.z -= up_accel;
if (velocity.z < -0.5 ) velocity.z = -0.5;
if (llGetPos() * <0,0,1> < llGround(ZERO_VECTOR) + max_fwd * velocity.z + hover_height)
velocity.z = 0.0;
} else {
velocity.z *= inertia;
if (llGetPos() * <0,0,1> < llGround(ZERO_VECTOR) + max_fwd * velocity.z + hover_height)
velocity.z = 0.0;
}

if (down & CONTROL_LEFT)
{
if (velocity.y < 0.0) velocity.y = 0.0;
velocity.y += left_accel;
if (velocity.y > 0.5 ) velocity.y = 0.5;
} else if (down & CONTROL_RIGHT)
{
if (velocity.y > 0.0) velocity.y = 0.0;
velocity.y -= left_accel;
if (velocity.y < -0.5 ) velocity.y = -0.5;
} else {
velocity.y *= inertia;
}

if (down & CONTROL_ROT_LEFT)
{
if (rotacity < 0.0) rotacity = 0.0;
rotacity += rot_accel;
if (rotacity > 0.5 ) rotacity = 0.5;
} else if (down & CONTROL_ROT_RIGHT)
{
if (rotacity > 0.0) rotacity = 0.0;
rotacity -= rot_accel;
if (rotacity < -0.5 ) rotacity = -0.5;
} else {
rotacity *= moment;
}

llSetColor(velocity * llGetRot() + veloff, hidden_face);
llSetAlpha(rotacity + 0.5, hidden_face);
}
}
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
Corporal Candour
Registered User
Join date: 3 Sep 2005
Posts: 38
01-31-2006 15:43
I have to say I was skeptical at first, but this is outstanding! Great job!!

However, is there a more efficient way other than having 4 scripts for each control, like perhaps fetching the same script 4 times?
Zodiakos Absolute
With a a dash of lemon.
Join date: 6 Jun 2005
Posts: 282
01-31-2006 15:59
I assume the reason for having multiple scripts of the same type is to alleviate the built-in delays in llSetPos and related commands. The delays are per script.
Brookston Holiday
Registered User
Join date: 29 May 2005
Posts: 58
02-06-2006 01:14
Hey there, thank you very much for this script, i was just trying version 2 when i found this post...

I have a couple questions:

Is it similar to the last version where as you put copies of each of the move/turn/rot etc scripts into the parent prim of each of your objects; and the control script into a child prim?

What is the hidden face number, do you need a prim with a hidden face in each object?


Thanks,
Brookston
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
02-06-2006 01:46
From: Brookston Holiday
Is it similar to the last version where as you put copies of each of the move/turn/rot etc scripts into the parent prim of each of your objects; and the control script into a child prim?

Multimove IS NOT Nonphy. You're confusing two very different things :(

Multimove, which is the set of scripts you're refering to here, currently in version 2, is designed to make builds composed of many objects move as one. Nonphy is designed to make ONE complex object move as a physical one.

From: Brookston Holiday
What is the hidden face number, do you need a prim with a hidden face in each object?

This hidden_face number is the number of the face of the root prim that is used to transmit movement information from the Nonphy script to all the movement and rotation scripts. Basically, the nonphy script changes the color and transparency of this face, and the other scripts read it and convert it to movement information. This is why it should be hidden (like the inside face of a hollowed-out sphere, for example), otherwise it might look ugly.
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
Ledje Gorky
Registered User
Join date: 1 Jun 2005
Posts: 126
02-06-2006 04:06
oh thank you thank you thnk you !!!

ive been looking all over to find these :p
Maklin Deckard
Disillusioned
Join date: 9 Apr 2005
Posts: 459
05-28-2006 11:18
From: Jesrad Seraph
Multimove IS NOT Nonphy. You're confusing two very different things :(

Multimove, which is the set of scripts you're refering to here, currently in version 2, is designed to make builds composed of many objects move as one. Nonphy is designed to make ONE complex object move as a physical one.


This hidden_face number is the number of the face of the root prim that is used to transmit movement information from the Nonphy script to all the movement and rotation scripts. Basically, the nonphy script changes the color and transparency of this face, and the other scripts read it and convert it to movement information. This is why it should be hidden (like the inside face of a hollowed-out sphere, for example), otherwise it might look ugly.


Well, it was working fine for me, but now every time I cross a sim line, its 50/50 it explodes into 240 unlinked pieces...usually half in one area, the other half shot all over the zone I just entered. Have I configured it wrong?
Lecina Enigma
Linux Client User-x86_64
Join date: 16 Nov 2005
Posts: 32
05-28-2006 17:22
It`s as i know from a AubreTEC Osprey Issue, and SL related thing. The Osprey plosed sometimes too in all parts on Sim zoning.
Angela Salome
Registered User
Join date: 6 Oct 2005
Posts: 224
05-30-2006 04:55
From: Maklin Deckard
...but now every time I cross a sim line, its 50/50 it explodes into 240 unlinked pieces...usually half in one area, the other half shot all over the zone I just entered. Have I configured it wrong?


No. It's likely that your object is near or at link range limits, so when it goes over the border of a sim into another with lag, the link distance is exceeded, and your object falls apart.
Halo Hienzman
Registered User
Join date: 31 Jul 2006
Posts: 2
07-31-2006 11:24
Is there any way to make it so you cant go into the air, but still go up hills like a car?
Marcus Quartermass
Registered User
Join date: 13 Feb 2005
Posts: 2
09-17-2006 03:48
Just a small problem with this script, that i came up with... Is it all supposed to be this jerky? I mean, with mouselook, everything turns with something like 30 degree jumps, making controlling it nigh impossible. It's like it's only updating everything once every half a second or so...

This of course, could be a lag issue too, feels like one at least. Especially since the ping times are always going to be at least 200-300ms minimum here, to the other side of the Atlantic.

I did try to fiddle around with the script a bit, but didn't really get it to perform any better, so for the time being, i'm afraid i'm restricted to physics enabled craft only, which is kinda sad combination with the 31 prim limit and my hyperactive imagination. And even the physics work like... ...well they don't, really, with the lag and all.

So, anyone have any thoughts on the potential reasons for the scripts rather poor performance on me, or ways of making it to do any better?

Alternative ways of getting more than 31 prims in the air are of course always welcome too!


...Other than that, excellent job with the script, does so much while still being nice and simple!
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
09-17-2006 04:37
I found something similar. The trick for me (and I'm on the European side of the pond too) was small, delicate control movements. Large movements had me spiralling all over the place.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog
Rich Cordeaux
Registered User
Join date: 8 May 2006
Posts: 26
09-17-2006 09:22
Mouselook with this script basically works like mouselook in Freelancer (the vehicle turns towards the mouse, and keeps turning until you put the mouse back in the 'center'), and the reason is that when the vehicle rotates towards the camera angle, you rotate with it, and the camera, which is attached to you, rotates as well. So the vehicle can never actually reach the camera, so it keeps turning.

You could check the magnitude of the rotation vector and resize it to a small value if you want it to always have smooth turning in mouselook.

(As for knowing when the mouse is centered, I made a script which can figure out when it's centered and place a reticle (crosshair) there to show you later. It has to be redone if your height changes (or if you give the vehicle to someone else), and sometimes it gets out of place for no apparent reason and has to be redone. It was also much harder to make than I expected.)

Theoretically if you could have the avatar sit on a different prim than the root one, and when you rotate the root prim, rotate the seat prim by the opposite amount, then it should change it to working like mouselook normally does. However, synchronizing those rotations may be a bit of a problem.
Burke Prefect
Cafe Owner, Superhero
Join date: 29 Oct 2004
Posts: 2,785
09-18-2006 07:40
From: Rich Cordeaux
Mouselook with this script basically works like mouselook in Freelancer (the vehicle turns towards the mouse, and keeps turning until you put the mouse back in the 'center'), and the reason is that when the vehicle rotates towards the camera angle, you rotate with it, and the camera, which is attached to you, rotates as well. So the vehicle can never actually reach the camera, so it keeps turning.


... DOH! I thought I was being an idiot when I saw that. I snipped out the mouselook for that reason (and cause I wasn't sure I'd need it) but I'll definitely add it back in as a mode toggle now. :D

Jesrad, your Nonphy is complete sweetness. I want to have your babies.
Wait... no, I'm the dude, you're the woman, so.... bah, you get the idea.
_____________________
FoxBlade Teazle
Fire Cures Everything
Join date: 20 Sep 2005
Posts: 31
09-18-2006 11:37
From: Maklin Deckard
Well, it was working fine for me, but now every time I cross a sim line, its 50/50 it explodes into 240 unlinked pieces...usually half in one area, the other half shot all over the zone I just entered. Have I configured it wrong?


You might want to try letting go of accelerate just before hitting a border and drifting across, this was something a friend and I had to do with the last script.
Desiree Allen
Registered User
Join date: 18 Mar 2007
Posts: 3
03-28-2007 23:47
Hi sorry i am new to SL but i have been harrased by someone orbiting me and teleporting me around what do i do with these scripts and where do i copy them to? please help i need help someone keeps sending me millions of messages and textures.
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
03-29-2007 05:06
I'm not sure what the nonphysical has to do with that unless you're just wanting a vehicle that can't be orbitted, but I would recommend filing an abuse report asap.
Alicia Mounier
Registered User
Join date: 17 Oct 2005
Posts: 78
Griefers suck and need to be spanked!!!!
03-29-2007 10:22
From: Desiree Allen
Hi sorry i am new to SL but i have been harrased by someone orbiting me and teleporting me around what do i do with these scripts and where do i copy them to? please help i need help someone keeps sending me millions of messages and textures.

Best you can do is contact Customer Support or maybe make an alt and try to get ahold of a Linden ingame and explain the situation.
Drake Shiras
Registered User
Join date: 20 Aug 2006
Posts: 4
05-09-2007 09:10
Hi. I dropped these scripts into a vehicle, and the only modifications i made to the scripts were to change the hidden face # to 1, and modify the camera angle. When the scripts start, i get this message

[9:00] Object: Script run-time error
[9:00] Object: Math Error
[9:00] Object: Script run-time error
[9:00] Object: Math Error
[9:00] Object: Script run-time error
[9:00] Object: Math Error
[9:00] Object: Script run-time error
[9:00] Object: Math Error
[9:00] Object: Script run-time error
[9:00] Object: Math Error
[9:00] Object: Script run-time error
[9:00] Object: Math Error
[9:00] Object: Script run-time error
[9:00] Object: Math Error
[9:00] Object: Script run-time error
[9:00] Object: Math Error

Furthermore, i cannot move the vehicle forward, back, up or down; only turn it left and right and with mouselook. Is there any possible explanation for this?
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
05-09-2007 10:53
Did you go through each of the other scripts and change the hidden face as well?

All scripts are set to running in the engine (root) prim?

Also, how big is the ship you put this in? Sometimes overly large ones can have this problem or they will *break* and fall apart when you cross a sim line.
SVAndrei Baxton
Registered User
Join date: 29 Aug 2008
Posts: 1
11-18-2008 08:56
Where exactly to you have to put each script, and how do you pilot the ship? i put all scripts in the root prim, entered mouselook, and nothing happens. Same thing happens without mouselook. Any advice? Thanks.