Difference between revisions of "PRIM MATERIAL"
Jump to navigation
Jump to search
Video tutorial about material
m |
m |
||
Line 153: | Line 153: | ||
|cat1=Prim | |cat1=Prim | ||
|cat2=Collision | |cat2=Collision | ||
|cat3 | |cat3=Prim/Materials | ||
|cat4 | |cat4 | ||
|{{#vardefine:comment}} | |{{#vardefine:comment}} | ||
}} | }} |
Revision as of 11:06, 24 April 2009
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Description
Constant: integer PRIM_MATERIAL = 2;<videoflash>6OXYO61kQCA</videoflash>
The integer constant PRIM_MATERIAL has the value 2
Sets the prim material. Material does not affect mass, but does affect friction, bounce (elasticity), and collision sound. On a wood incline of 33 degrees, the example script below gave the following results:
Type | Velocity (m/s) | Distance (m) |
---|---|---|
Stone | 0.453181 | 0.361655 |
Metal | 5.475444 | 10.211180 |
Glass | 6.483150 | 11.678304 |
Wood | 2.154549 | 9.433724 |
Flesh | 0.351543 | 0.188043 |
Plastic | 4.502428 | 9.590952 |
Rubber | 0.374964 | 0.187106 |
llSetPrimitiveParams
[ PRIM_MATERIAL, integer material ]• integer | material | – | PRIM_MATERIAL_* flag |
When used with llSetPrimitiveParams & llSetLinkPrimitiveParams
llGetPrimitiveParams
llGetPrimitiveParams([ PRIM_MATERIAL ]);Returns the list [ integer material ]
• integer | material | – | PRIM_MATERIAL_* flag |
Caveats
Related Articles
Constants
|
Functions
• | llSetPrimitiveParams | |||
• | llSetLinkPrimitiveParams | |||
• | llGetPrimitiveParams |
Events
• | changed |
Examples
<lsl>// © 2008 by Karzita Zabaleta // Author of Scripting Your World, Wiley, October 2008.
list gMaterialTypes = [
"STONE", "METAL", "GLASS", "WOOD", "FLESH", "PLASTIC", "RUBBER"
];
vector gHomePosition; rotation gHomeRotation; integer gWaitCount = 0; float gMaxVelMag; integer gPrimMaterial;
moveTo(vector origin, vector destination) {
float dist = llVecDist(origin, destination); integer passes = llCeil( llLog(dist/10.0) / llLog(2.0) ); integer i; list params = [PRIM_POSITION, destination]; for (i=0; i<passes; i++) { params = (params=[]) + params + params; } // actually move the prim, now llSetPrimitiveParams(params);
}
returnHome() {
llSetStatus(STATUS_PHYSICS, FALSE); moveTo(llGetPos(),gHomePosition); llSetTimerEvent(0); llSetRot(gHomeRotation);
}
calculate_velocity() {
float velMag = llVecMag(llGetVel()); if (velMag > gMaxVelMag) { gMaxVelMag = velMag; }
}
default {
state_entry() { gHomePosition = llGetPos(); gHomeRotation = llGetRot(); } on_rez(integer _n) { llResetScript(); } touch_start(integer n) { gMaxVelMag = 0; llSetPrimitiveParams([PRIM_MATERIAL, gPrimMaterial]); llSetStatus(STATUS_PHYSICS,TRUE); llSetTimerEvent(0.1); llResetTime(); gWaitCount=0; gPrimMaterial++; if (gPrimMaterial == 7 ) gPrimMaterial = 0; } timer() { calculate_velocity(); gWaitCount++; if (gWaitCount > 100) { // 10 seconds string type = llList2String( gMaterialTypes, gPrimMaterial-1 ); llOwnerSay(type+" reached maximum velocity of "+(string)gMaxVelMag+ " and traveled "+(string)llVecDist(llGetPos(), gHomePosition)+" meters."); returnHome(); } }
}</lsl>