Talan Mackenzie
The Rocketeer
Join date: 15 Aug 2004
Posts: 14
|
11-16-2004 05:28
I'm trying to build a very basic model car which will use sensor calls to locate specific objects or people, turn toward them, then drive over to them. I'd like to use vehicle script to make a nice smooth acceleration and decceleration (impulse is ugly), but vehicle script and llLookAt don't seem to get along well at all.
Case in point: vehicle script wants to drive toward the X axis, while llLookAt wants to point the Z axis toward the target. I've used llSetVehicleRotationParam( VEHICLE_REFERENCE_FRAME to reorient the vehicle model such that it both points -and- drives toward the Z axis now, however, the pointing is very rocky, jerky, and never quite makes it to the facing. (It always tires out about 10 degrees away. Furthermore, it only seems to drag itself about 15 more degrees each time llLookAt is called. [Being called by a sensor repeat.])
The toy car is about a meter long, has physics, and does not hover or fly. My llLookAt values are .5 and .1 right now, with my experiments showing no significant improvement no matter what I set them to (though this was hampered by my not fully understanding what those parameters on llLookAt are to begin with).
So, what could be causing this bizarre rocky LookAt? And should I even be using these functions at all? I thought about using the angular motor to turn the car, but couldn't come up with a good way to make it turn -toward- a target, instead of just left or right.
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
11-16-2004 06:18
also don't forget to stop you llLookAt as your object will always look at that point even as it moves if you don't (llStopLookAt, but you don't need to call it if your just calling llLookAt again) from the wiki... // AXIS_* constants, represent the unit vector 1 unit on the specified axis. vector AXIS_UP = <0,0,1>; vector AXIS_LEFT = <0,1,0>; vector AXIS_FWD = <1,0,0>;
// getRotToPointAxisAt() // Gets the rotation to point the specified axis at the specified position. // @param axis The axis to point. Easiest to just use an AXIS_* constant. // @param target The target, in region-local coordinates, to point the axis at. // @return The rotation necessary to point axis at target. // Created by Ope Rand, modifyed by Christopher Omega rotation getRotToPointAxisAt(vector axis, vector target) { return llGetRot() * llRotBetween(axis * llGetRot(), target - llGetPos()); }
// Strength and damping are values used to control how llRotLookAt and llLookAt move, these values are tunable. float strength = 1.0; float damping = 1.0;
default { state_entry() { vector target = <10, 20, 30>; // A vector to look at.
// These two lines are equivelant, and point the up (Z) axis at the target: llRotLookAt(getRotToPointAxisAt(AXIS_UP, target), strength, damping); llLookAt(target, strength, damping);
// This line points the fwd (X) axis at the target: llRotLookAt(getRotToPointAxisAt(AXIS_FWD, target), strength, damping);
// This line points the left (Y) axis at the target: llRotLookAt(getRotToPointAxisAt(AXIS_LEFT, target), strength, damping); } }
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Kermitt Quirk
Registered User
Join date: 4 Sep 2004
Posts: 267
|
11-16-2004 18:54
In regards to your comment about llApplyImpulse giving messy movement, I think there's also a solution to that which I've used once before. Have a look at this little function (which is on the wiki on the llApplyImpulse page) setVel(vector newVel, integer localAxis) { vector curVel = llGetVel(); if(localAxis) { rotation rot = llGetRot(); curVel /= rot; // Un-rotate curVel. }
newVel -= curVel; newVel *= llGetMass();
llApplyImpulse(newVel,localAxis); }
I found that by calling this function on a timer you can keep an object moving at a constant velocity for as long as you like. Since you're aiming at a target object, it also means you can calculate the distance to the target, and decrease the velocity as you get closer (i.e slow down to stop). I didn't ever do any real tests to see how efficient this method was but it definately works, and gives you very smooth automatic travel over any distance. As an added bonus it has no side effects when crossing sim boundries.
|