RC car wheels?
|
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
|
07-30-2009 17:50
I found a script that I've been trying to toy with for an RC car. Works alright, except I have one complaint. I don't think there's a way to make the wheels turn when the thing is in motion. Anyone have any ideas?
///////////////////////// //Remote Control Script// //Created By JoJo Hesse// ///////////////////////// ///////////// //To Use It// ///////////// //1.) Just Put It In Your Vehicle And Touch It //2.) Click "Yes" //3.) When You Finish Playing With It, Touch It Again And Click "No"
float speed=15; //Driving Speed. float TurnSpeed=140; //Turning Speed
default { on_rez(integer start_param) { llSetPos(llGetPos() + < 0,0,1>); //Move Up 1m So The Car Doesnt Get Stuck In Objects llResetScript(); //Reset The Script And Trigger state_entry() } state_entry() { llSetTouchText("Touch"); //Set Text For The "Touch" Button In The Pie Menu llSetSitText("Sit"); //Set Text For The "Sit" Button In The Pie Menu llSitTarget(< 5, 5, 5>, ZERO_ROTATION); //Offset To Sit On The Object (up to 300m on any axis) llSetVehicleFlags(2); llSetVehicleType(VEHICLE_TYPE_CAR); llSetVehicleFlags(VEHICLE_FLAG_LIMIT_ROLL_ONLY); llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.8); llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.5); llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 0.1); llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 0.8); llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1.8); llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 0.5); llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.11); llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.8); llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, < 1000.0, 2.0, 1000.0>); llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, < 10.0, 2.0, 1000.0>); llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 1); llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 0.1); llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, -1); llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.5); llCollisionSound("", 0.0); } changed(integer change) { //Unsit Person if (change & CHANGED_LINK) { key agent = llAvatarOnSitTarget(); if (agent) { llWhisper(0, "Please Dont Sit On Me..."); llUnSit(agent); } } } touch_start(integer num) { if(llDetectedKey(0)==llGetOwner()) //Only Activate For Owner llRequestPermissions(llGetOwner(),PERMISSION_TAKE_CONTROLS); //Request Owners Permissions } run_time_permissions(integer perm) { if (perm) { llSetStatus(STATUS_PHYSICS, TRUE); //Set Object Physical llTakeControls(CONTROL_UP | CONTROL_DOWN | CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT, TRUE, FALSE); //Take The Controls Of Owner } else { llSetStatus(STATUS_PHYSICS, FALSE); //Set Object Non-Phys llReleaseControls(); //Release Controls So Owner Can Move Around } }
control(key id, integer level, integer edge) { vector angular_motor;
if(level & CONTROL_FWD) { llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, < speed,0,0>); //Drive Forward } if(level & CONTROL_BACK) { llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <-(speed - 5),0,0>); //Drive In Reverse } if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT)) { angular_motor.x += TurnSpeed; angular_motor.z -= TurnSpeed; } if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT)) { angular_motor.x -= TurnSpeed; angular_motor.z += TurnSpeed; } llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor); //Apply Angular Motor(turn vehicle) } }
|
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
|
07-30-2009 17:53
Nevermind, found the problem- the reverse speed call.
|
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
|
07-30-2009 17:57
A better question is, is there any way to make the weels animate when the vehicle moves?
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
08-01-2009 05:11
Some work may be involved. There are sorta two independent decisions to be made about how to get the wheels spinning: what to use for the effect, and how to update the spin rate to correspond to the speed and direction of vehicle motion.
Depending on the prim(s) used for the wheels, it may be possible to get away with llSetTextureAnim() to make them appear to spin. That's best-case, but if one is stuck with sculpty wheels (among other prim types with unforgiving texture mappings), llTargetOmega() is necessary. The latter is laggier (it's a physical object, so llTargetOmega() is not all viewer-side in this case), and can lead to some moderately hairy rotation calculations for wheels that not only spin, but turn in the direction the vehicle is supposed to be turning.
Updating the spin rate may be by timer() event, and/or in response to control() settings. More often than not, a complex vehicle script will end up with a timer running anyway, so getting the vehicle velocity and telling the wheels about it (mumble) times a second isn't uncommon.
The most aggravating part of all this is that, for either the texture animation or llTargetOmega effect, there's no way to generate the effect on a linked prim directly from the vehicle script itself, but rather through llMessageLinked() to per-wheel scripts, adding to the total script memory footprint of the object (and the sim). In the case of an RC "vehicle", that means future script memory limits will apply to the parcel on which the thing is running, so there will be no venturing into microparcels nor already script-intensive land. (Ride-able vehicles, in contrast, will have to fit within the avatar's memory limits, wherever they may roam.)
|
jeaniesing Trilling
Loves to animate & script
Join date: 21 Oct 2006
Posts: 61
|
08-01-2009 15:58
I would suggest you go for the texture anim as you cannot have a taget Omega effect in a linked prim  give it a hubcap 
_____________________
  Pinastri/113/171/30
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
08-01-2009 16:23
From: jeaniesing Trilling you cannot have a taget Omega effect in a linked prim sure you can.... and on child prims in a linked physical object the effect is still client-side
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
|
08-02-2009 01:22
I don't mind having the texture be animated. What goes into something like that, to make it animate when the car moves?
|
Dekka Raymaker
thinking very hard
Join date: 4 Feb 2007
Posts: 3,898
|
08-02-2009 04:54
I didn't think you could turn anim smooth off and on, the animation is always in the moving state isn't it? I guess you could swap wheels from static to moving, but I can't even swap prims yet!
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
08-02-2009 06:19
From: Paul Wardark I don't mind having the texture be animated. What goes into something like that, to make it animate when the car moves? A basic mechanism is, in the control event where you deal with what happens if(level & CONTROL_FWD) and so on, also to send a link message to the wheels, telling them what's going on, and have the receiver scripts in the wheels stop, or start with the appropriate parameters to make it go forward or back, the texture animation for that wheel. You can get a lot more sophisticated with vehicle wheels, but that's where you start from.
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
08-02-2009 06:45
From: Dekka Raymaker I didn't think you could turn anim smooth off and on, the animation is always in the moving state isn't it? To turn it off, just use FALSE as the first argument (integer "mode"  to llSetTextureAnim(). (This does require a script in the prim to turn the animation on and off, whereas no script need remain in a prim once animation is started, if it never has to stop.) The main limitation of texture animation is that it either applies to all faces, or to just one. That's okay if your wheel prim is, say, a torus (and you can animate the one visible face), or maybe a cylinder or tube (and you just want to rotate the textures of the round ends, and don't mind rotating the "tire" surface on the side, too), but it's not possible to get the ends rotating and the side translating at the same time. Of course you can use more prims each with different texture animation properties, but prims are dear in vehicles. From: Void Singer on child prims in a linked physical object the effect is still client-side Thanks, Void, that's very good to know. I feel a little less guilty about using llTargetOmega, knowing that.
|