Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Making a Nonphysical Vehicle Throttle

Ronin Arnaz
Registered User
Join date: 6 Jun 2005
Posts: 41
03-08-2007 12:26
I was wondering Jesrad's NonPhyscal movement script could be modified to have a variable throttle?

For instance, with the default script, holding CONTROL_FWD will make the vehicle accelerate, but it will stop when released. What I'd like is to be able to press CONTROL_FWD to make the vehicle begin moving forward, with every additional press increasing the velocity.

Likewise, CONTROL_BACK will decrease the speed, or bring the vehicle to a stop.

The script in question: /54/65/85562/1.html
Ronin Arnaz
Registered User
Join date: 6 Jun 2005
Posts: 41
03-09-2007 14:55
*bump*

I've tried two methods already. One was changing the parameters in the if CONTROL_FWD statement, though I'm not terribly familiar with how it works. I also tried a while loop on the velocity auto-increment.
Ronin Arnaz
Registered User
Join date: 6 Jun 2005
Posts: 41
03-10-2007 21:47
*bump*
Ronin Arnaz
Registered User
Join date: 6 Jun 2005
Posts: 41
03-13-2007 05:20
*bump*
Sterling Whitcroft
Registered User
Join date: 2 Jul 2006
Posts: 678
03-13-2007 17:03
I looked at the code...doesn't it already do what you want?

In last script at this point:

"velocity.y += left_accel;"

Isn't the acceleration applied in steps, from 0 to .13, .26, .39, to .5?

...and similar Plus and Minus accelerations throughout the script.?
==========
Are you trying to get the RATE of acceleration to increase?
as in:
first forward arrow, Speed=.1 (total speed=.1)
second fwd arrow, Speed=Speed+.2 (total speed=.3)
third fwd arrow, Speed=Speed+.4 (total speed=.7)
fourth fwd arrow, Speed=Speed+.8 (total speed=1.5)
Ronin Arnaz
Registered User
Join date: 6 Jun 2005
Posts: 41
03-14-2007 12:14
From: Sterling Whitcroft

Are you trying to get the RATE of acceleration to increase?
as in:
first forward arrow, Speed=.1 (total speed=.1)
second fwd arrow, Speed=Speed+.2 (total speed=.3)
third fwd arrow, Speed=Speed+.4 (total speed=.7)
fourth fwd arrow, Speed=Speed+.8 (total speed=1.5)


Yes, I believe we are on the same page here. Just to clarify, this is exactly what I want the craft to do.

1. The craft is motionless when I hop in the pilot seat.

2. When I press the forward arrow, the craft begins moving. The craft remains at that speed even after I release the arrow.

3. When I press the forward arrow again, the craft moves to its next pre-determined speed.

4. When I press the back arrow, the craft slows to the previous speed.

5. When the craft is at its lowest forward speed, and I press the back arrow, the craft stops.

Sorry about the long-winded explanation, I just want to be perfectly clear.
Ronin Arnaz
Registered User
Join date: 6 Jun 2005
Posts: 41
03-15-2007 10:36
*bump*
Sterling Whitcroft
Registered User
Join date: 2 Jul 2006
Posts: 678
03-15-2007 17:54
hahaha
I still can't tell what the problem is.

As I read the script, it already works as follows:

From a standing start,
Press Up Arrow and speed becomes .13
Press Up Arrow and speed becomes .25
Press Up Arrow and speed becomes .37
Press Up Arrow and speed becomes .50
Press Up Arrow and speed remains .50
Press Down Arrow and speed becomes .37, etc.


Is that NOT what you want?

====== in the MAIN script, the code area below does this I think====
/PHP
if (down & CONTROL_FWD)
{
if (velocity.x < 0.0) velocity.x = 0.0;
velocity.x += fwd_accel;
if (velocity.x > 0.5 ) velocity.x = 0.5;
} else if (down & CONTROL_BACK)
{
if (velocity.x > 0.0) velocity.x = 0.0;
velocity.x -= fwd_accel;
if (velocity.x < -0.5 ) velocity.x = -0.5;
} else {
velocity.x *= inertia;
}

if (down & CONTROL_UP)
{
if (velocity.z < 0.0) velocity.z = 0.0;
velocity.z += up_accel;
if (velocity.z > 0.5 ) velocity.z = 0.5;
} else if (down & CONTROL_DOWN)
// etc.
/PHP
Gaius Goodliffe
Dreamsmith
Join date: 15 Jan 2006
Posts: 116
03-15-2007 18:19
Actually, that's what that logic would do, IF it were located in the control event. Notice, however, that the segment you've pasted from is in the timer event. It's doing that not in response to the key presses, but rather at time intervals if those keys had been pressed.

Basically, want you want to do is take that same logic and move it into the control event and get rid of the timer event. You also want to be doing this in response to changes in the edge, not just the level, of the key, otherwise it'll pop forward or back several levels rather than just one for each keypress.

E.g. something like this:
CODE

if ( level & edge & CONTROL_FWD )
{
if ( throttle < 100 )
{
throttle += 10;
llSay(0, "Throttle: " + (string)throttle + "%");
}
}
if ( level & edge & CONTROL_BACK )
{
if ( throttle > -20 )
{
throttle -= 10;
llSay(0, "Throttle: " + (string)throttle + "%");
}
}

(That's from the control script of the Vagabond. Alas, I don't use Jesrad's scripts, so I don't have drop in examples to use with those.)
Ronin Arnaz
Registered User
Join date: 6 Jun 2005
Posts: 41
03-15-2007 20:33
Thanks Gaius! I knew it had to be something pretty simple that I was missing.

I noticed the same thing Sterling did, and had wondered exactly why the script didn't do that already.