Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Noob question about movement

Patryk Stirling
Registered User
Join date: 30 Jul 2004
Posts: 26
12-10-2004 14:36
Naming my thread like that is an easy way to say "hey don't laugh at me, but I can't find the right way to write this code ! :( " lol

Well, what I want to do is that when I say IE "left" to an object, it moves left by a certain distance.

I already find how to use the llListen function to make my object listen and responding at my orders, but my problem is for the movement it self...

Maybe llApplyImpulse ??? Maybe but I don,t really understand how to use it ... HELP PLZ !!! :confused:

Edit : And please if you write a code, comment it because I want to learn it, not just copy/paste ... TY !
Driftwood Nomad
Registered User
Join date: 10 May 2003
Posts: 451
12-10-2004 15:43
llApplyImpulse is only for physical objects.

For non-physical objects, things are easier. Just set a position offset. For example:

CODE

vector currentPos = llGetPos(); // Gets the current position of the object
vector offsetPos = <0,2,0>; // Creates an offset vector of 2 meters on the Y axis
vector finalPos = currentPos + offsetPos; // Creates final position
llSetPos(finalPos); // Moves the object to that position
_____________________
Driftwood Nomad
D&D Dogs Co-founder

"Second Life’s first AI companion animal"
The Second Opinion, 08/05/2003

D&D Dogs HQ Pawaii (127, 63)
Mainland Store Kuula (214, 124)

http://www.sldogs.com

SL Dogs Zazzle store!
Patryk Stirling
Registered User
Join date: 30 Jul 2004
Posts: 26
12-10-2004 15:58
Thanks, but the object is physical, I need to see it moving while it goes to point B.
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
12-10-2004 19:40
Blatantely stolen from Driftwood Nomad:

CODE

llStopMoveToTarget(); // Stop any current MoveToTargets, just in case
vector currentPos = llGetPos(); // Gets the current position of the object
vector offsetPos = <0,2,0>; // Creates an offset vector of 2 meters on the Y axis
vector finalPos = currentPos + offsetPos; // Creates final position
llMoveToTarget( finalPos, 1.0 ) ; // Moves the object to that position over 1 second


Tha'd work, woul'n it? :D
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Shack Dougall
self become: Object new
Join date: 9 Aug 2004
Posts: 1,028
12-10-2004 20:24
From: Cross Lament
Blatantely stolen from Driftwood Nomad:

CODE

llStopMoveToTarget(); // Stop any current MoveToTargets, just in case
vector currentPos = llGetPos(); // Gets the current position of the object
vector offsetPos = <0,2,0>; // Creates an offset vector of 2 meters on the Y axis
vector finalPos = currentPos + offsetPos; // Creates final position
llMoveToTarget( finalPos, 1.0 ) ; // Moves the object to that position over 1 second


Tha'd work, woul'n it? :D


A couple of things to keep in mind. Maybe not relevant here, but it should be noted.

1. llMoveToTarget will only move something up to 64m in a single call. If you need to move it a greater distance, then you will need to make more than one call. You might, for example, use llTarget to be notified when you are close to the end of your first move and then call llMoveToTarget again. Put this in a loop.

2. At some point, the whole mass/energy thing will bite you. The short description of this is that there comes a point at which an object is too heavy to move itself. A massive prim won't move at all. A prim on the border will move a little bit and then fall down. Make the prim smaller/thinner or hollow it.

3. small objects using llMoveToTarget won't move if more massive objects are attached to them. A good example of this is an elevator. if you make the floor of the elevator too light, then it won't move when an AV is standing on it.
_____________________
Prim Composer for 3dsMax
-- complete offline builder for prims and sculpties in 3ds Max
http://liferain.com/downloads/primcomposer/

Hierarchical Prim Archive (HPA)
-- HPA is is a fully-documented, platform-independent specification for storing and transferring builds between Second Life-compatible platforms and tools.
https://liferain.com/projects/hpa
Patryk Stirling
Registered User
Join date: 30 Jul 2004
Posts: 26
12-10-2004 22:27
Yeah it WORKS !!!! :eek:

But I have to put a distance of 50 insteed of 2 to really see it moving and it comes right back to its original position ?! That's ok, that's what I want but, why is it doing that ?

I'll put my code here and hope you can explain...

CODE
vector offset=<3,1,0.1>;
key pikac="cb61cd8a-d125-d6d7-8381-4ebeaab9618b";

startup()
{
vector pos=llGetPos();
llSetStatus (STATUS_PHYSICS, TRUE);
key id=llGetOwner();
llSensorRemove();
llSensorRepeat("",llGetOwner(),AGENT,20,2*PI,.5);
}

default
{
state_entry()
{
startup();
}
sensor(integer total_number)
{
vector pos=llDetectedPos(0);
llMoveToTarget(pos+offset*llDetectedRot(0),.3);
llLookAt(pos*106,.1,100);
llListen(0,"",llGetOwner(),"");
}

listen( integer channel, string name, key id, string message )
{
llWhisper(0,"OK,Master!");
llPlaySound(pikac,1);
if(message=="pkjump")
{
llStopMoveToTarget(); // Stop any current MoveToTargets, just in case
vector currentPos = llGetPos(); // Gets the current position of the object
vector offsetPos = <0,0,50>; // Creates an offset vector of 2 meters on the Y axis
vector finalPos = currentPos + offsetPos; // Creates final position
llMoveToTarget( finalPos, 2.0 ) ; // Moves the object to that position over 1 second
}
if(message=="pkleft")
{
llStopMoveToTarget(); // Stop any current MoveToTargets, just in case
vector currentPos = llGetPos(); // Gets the current position of the object
vector offsetPos = <50,0,0>; // Creates an offset vector of 2 meters on the Y axis
vector finalPos = currentPos + offsetPos; // Creates final position
llMoveToTarget( finalPos, 2.0 ) ; // Moves the object to that position over 1 second
}
if(message=="pkright")
{
llStopMoveToTarget(); // Stop any current MoveToTargets, just in case
vector currentPos = llGetPos(); // Gets the current position of the object
vector offsetPos = <-50,0,0>; // Creates an offset vector of 2 meters on the Y axis
vector finalPos = currentPos + offsetPos; // Creates final position
llMoveToTarget( finalPos, 2.0 ) ; // Moves the object to that position over 1 second
}
}
}
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
12-10-2004 23:49
well um what is the sensor suppose to do?
Patryk Stirling
Registered User
Join date: 30 Jul 2004
Posts: 26
12-11-2004 07:55
recognize the owner ... is it necessary ?

Because I want to sell these objects later... So when its rez, it needs to recognize the owner, no ? :confused:
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
12-11-2004 11:48
umm llGetOwner() returns the key of the avatar who owns the object. I could make the object move as you described with out it. So it seems like frivolous code, unless your planning to make it fallow some one.
Chalky White
Second Life Resident
Join date: 1 Nov 2004
Posts: 140
12-11-2004 12:11
Your problem seems to be that, regardless of what move may be commanded and under way, every half-second you again sense where your avatar is, and move the object back to a fixed offset from your avatar.
So of course none of your moves complete. They are countermanded every half second.
I may be wrong, but thats how it looks to me.
Patryk Stirling
Registered User
Join date: 30 Jul 2004
Posts: 26
12-11-2004 12:39
oh... That makes sense .... !

Sorry about that ! I'm a beginner.


I want that the objetc follow his owner and then when it enter in a state (when its touched it enter the special state) then it don't follow me and execute my moving orders. It need to come back to his original position but only when its moves are finished.

For the touch event, I want it to scan if theres a specify object around in 20 meters and if yes, it enter the special state. But when I touch the object, it doesn't no nothing. So what I got for now is this...


CODE
touch_start(integer total_number)
{
llSensor("", NULL_KEY, AGENT, 20, PI); // I want it to scan for specified objects names
}

sensor(integer total_number)
{
if(name=="The object aimed") // I don't know what to put at name's place ? it gives me an error.
{
llWhisper(0,"The object aimed detected"); // When my object will say this sentence, I will work on the special state
}
}



And THANKS guys that help me a lot ! I surf both wiki page and the forum thread to learn, but it's also harder because I'm french and I'm not FULLY bilingual.... You're nice ! ;)