2015年3月22日 星期日

SecondLife - LSL : ball bounce



We can set the ball as Physics, and set friction to 0, density to 1, restitution to 1,
then the ball can bounce for a while, meanwhile it will stop.


So we try to use LSL linden script way. 


----
----

With the script, the ball can bounce forever.
The video is as below :


script description : 


------

1. use sensor

At the first, I try to use sensor detection way : 


and write sensor() in default , to be called repeatedly

I use 
    - llGetVel : get current velocity
    - llVecMag : change velocity to magnitude

float speed = llVecMag(llGetVel());

If the velocity is zero ( < 0.001 ) then use 

    llSetPos(llGetPos() + <0,0,50>);


  - llGetPos

to move the object 50 higher again.

aware that llSetPos() is not workable for physical object
So we need to turn it off, and then turn on after setting

llSetStatus(STATUS_PHYSICS, FALSE);


2. use collision instead of sensor

When collision, we can invert the velocity

vector speed = llGetVel();
speed.z = speed.z * -1;
llSetVelocity(speed, FALSE);

but the ball will stopped also.. maybe the friction of the air...
So I set the fixed value for the velocity

llSetVelocity(<0,0,12>, FALSE);








沒有留言:

熱門文章