Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

This walk script almost works.....

Clintok Meyer
Registered User
Join date: 28 Apr 2006
Posts: 17
11-01-2007 15:07
When put into a prim and sat on, then pressing the forward arrow keys, my avatar does not move forward but walks in place. I need the avatar to move. Can someone look at this script and indicate what might be wrong please? Thank you

From: someone
//Copyright 2006 Zepp Zaftig - GNU Lesser General Public License http://www.gnu.org/copyleft/lesser.html
//This script or any modified versions of it may not be distributed without source code.

//Settings
//Edit these to configure the script
string WALKANIM = "female_walk"; //Name of the walk animation to use
string FLYANIM = "fly"; //Flying animation
string HOVERANIM = "hover"; //Hover animation
string UPANIM = "hover_up"; //Flying up animation
string DOWNANIM = "hover_down"; //Flying down animation
integer WALKSPEED = 1; //Change to an integer higher than 1 to walk faster
integer FLYSPEED = 10; //How many times faster the flying speed should be compared to default speed
integer PHANTOM = TRUE; //Set to TRUE for walking through solid objects, FALSE to disable
integer TOUCHABLE = TRUE; //Rotate 90 degrees on touch when set to TRUE
//End settings

float zoffset;
integer flying = FALSE;

default {
state_entry() {
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
llCollisionFilter(llKey2Name(llGetOwner()), llGetOwner(), FALSE);
vector avatarsize = llGetAgentSize(llGetOwner());
zoffset = avatarsize.z / 1.3;
llSitTarget(<0, 0, -0.5>, ZERO_ROTATION);
llCollisionSound("", 0);
}

changed(integer change) {
if(change & CHANGED_LINK) {
key agent = llAvatarOnSitTarget();
if(agent) {
if(agent != llGetOwner()) {
llUnSit(agent);
} else {
llSetAlpha(0, ALL_SIDES);
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
}
} else {
llSetAlpha(1, ALL_SIDES);
llSetStatus(STATUS_PHYSICS, FALSE);
llReleaseControls();
llResetScript();
}
}
}

run_time_permissions(integer perm) {
if(perm) {
llStopAnimation("sit";);
llStartAnimation("stand";);
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_UP | CONTROL_DOWN |
CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT, TRUE, FALSE);
}
}

control(key id, integer level, integer edge) {
//Any button pressed
if(edge & level) {
llSetStatus(STATUS_PHYSICS, TRUE);
llStopAnimation(HOVERANIM);
}

//Forward or backwards pressed
if(edge & level & (CONTROL_FWD|CONTROL_BACK)) {
if(flying == TRUE) {
llStartAnimation(FLYANIM);
} else {
llStartAnimation(WALKANIM); //Start the walk animation
}
}
//All buttons released
if((~level & CONTROL_FWD) && (~level & CONTROL_BACK) && (~level & CONTROL_RIGHT) &&
(~level & CONTROL_LEFT) && (~level & CONTROL_ROT_RIGHT) && (~level & CONTROL_ROT_LEFT)
&& (~level & CONTROL_UP) && (~level & CONTROL_DOWN) ) {

llTargetOmega(<0,0,0>, 0, 1);
llSetStatus(STATUS_PHYSICS, FALSE);

llSetPos(llGetPos()); //Workaround for weird prim movement behavior
llSetRot(llGetRot());

llStopAnimation(WALKANIM);
llStopAnimation(UPANIM);
llStopAnimation(DOWNANIM);
llStopAnimation(FLYANIM);
if(flying == TRUE) {
llStartAnimation(HOVERANIM);
} else {
llStartAnimation("stand";);
}
}
//Turning key released
if((~level & edge & CONTROL_RIGHT) || (~level & edge & CONTROL_LEFT) ||
(~level & edge & CONTROL_ROT_RIGHT) || (~level & edge & CONTROL_ROT_LEFT)) {
llTargetOmega(<0,0,1>, 0, 1);
llTargetOmega(<0,0,-1>, 0, 1);
}
//Turn right
if(level & edge & (CONTROL_RIGHT|CONTROL_ROT_RIGHT)) {
llTargetOmega(<0,0,-1>, PI / 3.5, 1);
//Turn left
} else if(level & edge & (CONTROL_LEFT|CONTROL_ROT_LEFT)) {
llTargetOmega(<0,0,1>, PI / 3.5, 1);
}
//Forward
if(level & CONTROL_FWD) {
vector pos;
if(flying == FALSE) {
pos = llGetPos() + WALKSPEED*llRot2Fwd(llGetRot());
pos.z = zoffset + llGround(ZERO_VECTOR);
} else {
pos = llGetPos() + FLYSPEED*llRot2Fwd(llGetRot());
}
llMoveToTarget(pos, 0.1);
//Backwards
} else if(level & CONTROL_BACK) {
vector pos;
if(flying == FALSE) {
pos = llGetPos() - WALKSPEED*llRot2Fwd(llGetRot());
pos.z = zoffset + llGround(ZERO_VECTOR);
} else {
pos = llGetPos() - FLYSPEED*llRot2Fwd(llGetRot());
}
llMoveToTarget(pos, 0.1);
}
//Flying
if(level & CONTROL_UP) {
flying = TRUE;
llStartAnimation(UPANIM);
llMoveToTarget(llGetPos() + <0,0,3.5>, 0.1);
} else if(level & CONTROL_DOWN) {
llStartAnimation(DOWNANIM);
vector pos = llGetPos();
if( (pos.z - llGround(ZERO_VECTOR)) < 2.5 ) {
flying = FALSE;
}
llMoveToTarget(llGetPos() - <0,0,3.5>, 0.1);
}
}

//Move through solid objects
collision(integer det_num) {
if(PHANTOM == TRUE) {
llSetStatus(STATUS_PHYSICS, FALSE);
llSetPos(llGetPos() + llRot2Fwd(llGetRot()));
llSetStatus(STATUS_PHYSICS, TRUE);
}
}

touch_start(integer det_num) {
if(TOUCHABLE == TRUE) {
llSetRot(llGetRot() * llEuler2Rot(<90*DEG_TO_RAD,0,0>;));
}
}
}
revochen Mayne
...says
Join date: 14 Nov 2006
Posts: 198
11-02-2007 00:21
Hi Clintok

Please change
From: someone

llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_UP | CONTROL_DOWN |
CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT, TRUE, FALSE);
In the run_time_permissions event
To:

llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_UP | CONTROL_DOWN |
CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT, TRUE, TRUE);

That should fix it! Enjoy =)
Cristiano Midnight
Evil Snapshot Baron
Join date: 17 May 2003
Posts: 8,616
11-02-2007 00:25
You seem to be mixing some metaphors in what you are trying to do. Are you just trying to override a walk? If so, you attach the object, you don't sit on it. Sitting on it would require using a vehicle to move you.
_____________________
Cristiano


ANOmations - huge selection of high quality, low priced animations all $100L or less.

~SLUniverse.com~ SL's oldest and largest community site, featuring Snapzilla image sharing, forums, and much more.

Clintok Meyer
Registered User
Join date: 28 Apr 2006
Posts: 17
11-02-2007 06:28
From: revochen Mayne
Hi Clintok

Please change
In the run_time_permissions event
To:

llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_UP | CONTROL_DOWN |
CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT, TRUE, TRUE);

That should fix it! Enjoy =)



Thank you, I will try it tonight.
Clintok Meyer
Registered User
Join date: 28 Apr 2006
Posts: 17
11-02-2007 06:34
From: Cristiano Midnight
You seem to be mixing some metaphors in what you are trying to do. Are you just trying to override a walk? If so, you attach the object, you don't sit on it. Sitting on it would require using a vehicle to move you.



You are correct and I might be stating this incorrectly. I *do* want to sit on it (thus it should be treated as a vehicle issue I guess).

I'm trying to make a two person hold hand and walking animation. I've seen other versions where two people click on balls and then "walk" together, but mine will be better *smile*.

I can script a bit if given examples, I can animate, and I can put it together but. The scripting part is the part that eludes me.

I hope this makes sense as it will make for a happy animation if I can pull it off.

Thank you
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
11-02-2007 07:44
By looking at the code it apepars to already be set to work physically, meaning sat on. Though it's not making a vehicle but using MoveTo instead...think that would be a bit wonky myself but *shrug*
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
11-02-2007 08:42
it is strange.


but i tried to use it to make something for my spider/shadow crawler to use to climb up walls and along ceilings. had a few problems.


1: when moving forward and pressing a turn key, it doesnt stop turning if the turn key is let up (until and unless the forward key also is.)


2: when clicking the object to change its angle of rotation...

A: it seems to rotate on the world axis, not its own? and

B: it seems to move on the wordl axis and not its own.


that is, if im facing south and click it, i turn to face down. if im facing west and click it i turn to lie on my left side.

at any 'off' orientation, i still go the regular forward/back. if im turning so i can go up a wall, i really want to go up/down instead.
and is there a way to roll the camera? when i was upside down, the camera was still upright. and turning was backwards.



zepp posted this script a LONG time ago. it sounds cool, though. if it would work how i envision ;) anybody feel like tinkering with it?

as for being physical... i think that's to prevent it from going through objects when not in 'ghost' mode. maybe? or for staying on the ground when going downhill? (something my non-physical 'vehicle' fails to do.)

also, wouldnt move to work better for uneven terrain? i know my 'walker vehicle' doesn't have enough engine thrust to go uphill when i set it to normal avatar walking speed. move to seems to be able to ignore uphill/downhill problems like that.
_____________________
Why Johnny Can't Rotate:
http://forums.secondlife.com/showthread.php?t=94705