Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
|
07-23-2005 20:02
Well...I'm still havin' trouble getting a vehicle to move with another object "on touch"...code follows: The following code is placed on a generic object that is moving and resizing through a couple other simple loop scripts...as they aren't relevant to the problem, they've been left out (movement and resizing is workin' just fine). The idea in this code is that when the object is touched, it senses whether there is an "attachable" object within 5 meters and if there is, sends its position to that object so the object can "follow" it exactly. touch_start(integer total_number) { llSensor("Object", NULL_KEY, ACTIVE | PASSIVE, 5, PI); } sensor(integer total_number) { string _moverPos = (string)llGetPos(); llWhisper(13, _moverPos); } }
The next object is a vehicle (vehicle script portions left out...we all know what they look like...heh). It has a listen and a loop to continue moving with the parent object as long as the parent object is within a certain range.
listen(integer channel, string name, key id, string message) { if(channel = 13) { vector _ride = (vector)message; llSetPos(_ride); llSensor("Mover", NULL_KEY, ACTIVE | PASSIVE, 1, PI); } } sensor(integer total_number) { integer _mover = 0; vector _ride = llDetectedPos(_mover); llMoveToTarget(_ride, .2); }
I know there's no loop there yet...but even the initial reposition doesn't work--and I'd like to figure that out first  Any/all help is greatly appreciated. I've been killin' myself over this problem for a couple weeks (I've got two previous posts about it without posting code--so figured I'd post code this time around).
|
Champie Jack
Registered User
Join date: 6 Dec 2003
Posts: 1,156
|
07-24-2005 04:53
well, it may not be pretty, but I'm sure you can make it work for you: default { state_entry() { // I have nothing here, but I'm sure you have something good to put here }
touch_start(integer total_number) { llSensor("Object", NULL_KEY, ACTIVE | PASSIVE, 5, TWO_PI); }
sensor(integer total_number) { string _moverPos = (string)llGetPos(); llWhisper(13, _moverPos); }
}
and: integer targetID; integer handle;
default { state_entry() { llSetStatus(STATUS_PHYSICS, FALSE); llSensorRemove(); llListenRemove(handle); handle = llListen(13,"","", ""); }
listen(integer channel, string name, key id, string message) { if(channel = 13) { vector _ride = (vector)message; llWhisper(0, (string)_ride); llSetPos(_ride); llSensorRepeat("Object", NULL_KEY, ACTIVE | PASSIVE, 5.0, TWO_PI, .25); } } sensor(integer total_number) { llTargetRemove(targetID); llStopMoveToTarget(); integer _mover = 0; vector _ride = (llDetectedPos(_mover)); targetID = llTarget(_ride, 1.0); float distance = llVecDist(llGetPos(), _ride); if (distance > 1.0) { llSetStatus(STATUS_PHYSICS, TRUE); llMoveToTarget(_ride, .5); } } at_target( integer number, vector targetpos, vector ourpos ) { llTargetRemove(targetID); llStopMoveToTarget(); llSetStatus(STATUS_PHYSICS, FALSE); } }
The two problems that could have been casuing the most pain for your were 1. Did you llListen(13, "","",""  ; in your original script? If not, then the follower could not hear the command to follow. 2. You have to llSetStatus(STATUS_PHYSICS, TRUE); in order to make llMoveToTarget to work. I added an at_target event that helps keep things in order. I also set a new target each time the Mover object is sensed. Hope this helps Champie
|
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
|
07-24-2005 07:07
Hmmm...thanks much.
If I could clarify on the physics questions:
1) Since item #2 (the one where you're setting the physics on and off) is a vehicle...I'm pretty sure the physics are already on once I decide to drive it. I'll add the further clarification your code provides...but just wanted to make sure...
2) Does item #1 also need physics set to true? You were saying that the llmovetotarget requires it, so I don't imagine so...but I'm just trying to cover any and all bases.
Thank you again for workin' through my code with me. I'll log in and see if it works right now.
Hmmm...didn't work.
I'm really wondering whether this whole difficulty stems from the fact that I'm attempting to attach a vehicle that is being ridden to a moving non-physical object? I don't know of any restriction to doing so...but I can't figure out anything else???
|
Champie Jack
Registered User
Join date: 6 Dec 2003
Posts: 1,156
|
07-24-2005 07:42
Hey Ken, I'm not sure why it didn't work for you...I've been chasing cubes all over the place on my land with the scripts.
I'd be happy to meet you in game to try to work out some of the issues. That way you could show me exactly what you doing and where it might be going wrong.
IM if you get a chance. I'm in game now
|
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
|
07-24-2005 12:24
GREAT! And thanks much. I just IMed you (12:23 PM SL time) and it looks like we just missed eachother. I'll look for you again.
|