Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Download Outerra Tech Demo. Unofficial Outerra Discord server, MicroProse Discord server for OWS.

Pages: 1 [2] 3 4 ... 8

Author Topic: Vehicle script [version 1.4.0]  (Read 81847 times)

M7

  • Hero Member
  • *****
  • Posts: 736
  • newbie
Re: Vehicle script [version 1.2]
« Reply #15 on: May 09, 2013, 12:03:38 am »

Well i just tried giucam manual transmission script (without clutch) with mLichy's Belair so i can test sounds on a manual transmission script  without the wobling. Only problem i can load the Belair only once, if i get off a cliff and have to reload a new one i get this error message.


But so far i just love the manual transmission script. I made some windy road in the mountains and the driving is great. Can wait to test the updated clutch version.
Logged

giucam

  • Full Member
  • ***
  • Posts: 171
  • It's an ugly pile of bones... like me.
Re: Vehicle script [version 1.2]
« Reply #16 on: May 09, 2013, 06:00:32 am »

Just tried it, didn't figured the clutch yet so i just put it to automatic clutch to quickly testdrive,  but in either mode, the car moves like  molass  ???
That is, the engine doesn't rev up? Only when starting or always? Are you starting in first gear?

Also i'm wondering if you could reimport the BMW and include another bone other than the wheels. I'd like to test other sounds using a manual transmission and the BMW being the only vehicle with  manual transmission. The problem is that you set the sound emiter to one of the wheel . Doesn't seems to be problematic with the default sound but when  replace it , it sound really weird  because when the wheel turn, the sound kind of woble.
That totally makes sense, but i don't know how to import the BMW, and i'd rather like not to learn to :P. I took the BMW imported by cameni, so if someone can import it again i'd be very thankful!

Quote
Well i just tried giucam manual transmission script (without clutch) with mLichy's Belair so i can test sounds on a manual transmission script  without the wobling. Only problem i can load the Belair only once, if i get off a cliff and have to reload a new one i get this error message.
Does that happen with the 1.2 script too?
Logged
ResidualVM 0.1.1 is OUT! www.residualvm.org

giucam

  • Full Member
  • ***
  • Posts: 171
  • It's an ugly pile of bones... like me.
Re: Vehicle script [version 1.2.1]
« Reply #17 on: May 09, 2013, 06:32:38 am »

Just tried it, didn't figured the clutch yet so i just put it to automatic clutch to quickly testdrive,  but in either mode, the car moves like  molass  ???   

I made a silly mistake when cleaning up the script, fixed now.
Code: [Select]
/*
    Vehicle script file
    Copyright (C) 2012 - 2013  Giulio Camuffo <giuliocamuffo@gmail.com>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public
    License as published by the Free Software Foundation; either
    version 3.0 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

//see http://xtrac.outerra.com/index.fcgi/wiki/vehicle for example and documentation

// VERSION 1.2.1

//invoked only the first time the model is loaded, or upon reload
function init_chassis(){
    var wheelparam = {
        radius: 0.30,
        width: 0.20,
        suspension_max: 0.1,
        suspension_min: -0.05,
        suspension_stiffness: 50.0,
        damping_compression: 0.06,
        damping_relaxation: 0.05,
        slip: 5.0,
        roll_influence: 0.1,
        rotation: -1
    };

    this.add_wheel('wheel_FL', wheelparam);
    this.add_wheel('wheel_FR', wheelparam);
    this.add_wheel('wheel_RL', wheelparam);
    this.add_wheel('wheel_RR', wheelparam);

    this.load_sound("e90_startup.ogg"); //startup
    this.load_sound("e90_onidle.ogg"); //idle
    this.load_sound("e90_offlow.ogg"); //off
    this.load_sound("e90_onlow.ogg"); //on
    this.basepitch = [ 1, 1, 0.4, 0.4 ];             //base pitch for start, idle, off, on
    this.add_sound_emitter("wheel_FL");

    //engine properties -- modify these to change the engine behaviour
    this.wheelRadius = 0.24;

    this.torquePoints = [ { rpm: 200,    torque: 0},
                          { rpm: 1000, torque: 250},
                          { rpm: 2000, torque: 335},
                          { rpm: 3000, torque: 380},
                          { rpm: 4000, torque: 400},
                          { rpm: 5000, torque: 395},
                          { rpm: 6000, torque: 400},
                          { rpm: 7000, torque: 390},
                          { rpm: 8000, torque: 365},
                          { rpm: 9000, torque: 0  } ];

    this.forwardGears = [ { ratio: 4.06, shiftUp: 8000, shiftDown: -1   },
                          { ratio: 2.40, shiftUp: 8000, shiftDown: 4500 },
                          { ratio: 1.58, shiftUp: 8000, shiftDown: 5000 },
                          { ratio: 1.19, shiftUp: 8000, shiftDown: 5500 },
                          { ratio: 1.00, shiftUp: 8000, shiftDown: 6000 },
                          { ratio: 0.87, shiftUp: -1,   shiftDown: 6000 } ];
    this.reverseGears = [ { ratio: 4.68, shiftUp: -1, shiftDown: -1 } ];

    this.differentialRatio = 3.85;
    this.efficiency = 0.9;
    this.speedLimiter = -1; // maximum speed in m/s. a value < 0 means there's no limiter
    this.engineBrakeCoefficient = 0.4;
    this.breakingForce = 5000.0;
    this.pitchMultiplier = 1.5;
    this.automaticTransmission = false;
    this.automaticClutch = true;
    this.engineInertia = 0.05;
    this.minimumRPM = 1000;
    this.minimum = 0.2;
    //end of engine properties

    this.maxPowerTP = this.torquePoints[0];
    this.maxRPM = 0;
    var maxPw = 0;
    for (var i = 1; i < this.torquePoints.length; ++i) {
        var tp = this.torquePoints[i];
        if (tp.rpm * tp.torque > maxPw) {
            this.maxPowerTP = tp;
        }
        if (tp.rpm > this.maxRPM) {
            this.maxRPM = tp.rpm;
        }
    }

    this.neutroGear = { ratio: 0.0, shiftUp: -1, shiftDown: -1, index: 0 };
    var prev = null;
    for (var i = 0; i < this.forwardGears.length; ++i) {
        var gear = this.forwardGears[i];
        if (prev)
            prev.next = gear;
        gear.prev = prev;
        gear.index = i + 1;
        prev = gear;
    }

    prev = null;
    for (var i = 0; i < this.reverseGears.length; ++i) {
        var gear = this.reverseGears[i];
        if (prev)
            prev.prev = gear;
        gear.next = prev;
        gear.index = -i - 1;
        prev = gear;
    }

    this.torque = engineTorque;
    this.shiftUp = shift_up;
    this.shiftDown = shift_down;
    this.selectGear = select_gear;
    this.die = die;
    this.updateAutomaticTransmission = automatic_transmission;
    this.animate = animate;

    return {mass:1570, steering:1.0, steering_ecf:10000, centering: 2.0, centering_ecf: 10};
}

//invoked for each new instance of the vehicle
function init_vehicle() {
    this.set_fps_camera_pos({x:-0.33,y:-0.25,z:1.15});

    this.snd = this.sound();
    this.snd.set_ref_distance(0, 9.0);

    this.started = false;
    this.gear = this.neutroGear;
    this.direction = 0;
    this.engineRPM = 0;
    this.appliedTorque = 0;
    this.starting = false;
    this.clutch = 0.0;
    this.clutchState = 1;
}

//invoked when engine starts or stops
function engine(start) {
    if (start) {
        this.started = false;
        this.soundId = 0;
        this.starting = true;
    } else {
        this.started = false;
    }
}

function engineTorque(rpm) {
    var min = 0;
    var max = this.torquePoints.length - 1;

    if (rpm > this.torquePoints[max].rpm || rpm < this.torquePoints[min].rpm)
        return 0;

    while (max - min > 1) {
        var mid = Math.floor(min + (max - min) / 2);
        var tp = this.torquePoints[mid];
        if (tp.rpm == rpm) {
            return tp.torque;
        } else if (tp.rpm > rpm) {
            max = mid;
        } else {
            min = mid;
        }
    }

    var minTp = this.torquePoints[min];
    var maxTp = this.torquePoints[max];
    var TM = maxTp.torque;
    var Tm = minTp.torque;
    var RM = maxTp.rpm;
    var Rm = minTp.rpm;

    var a = (TM - Tm) / (RM - Rm);

    return rpm * a + Tm - Rm * a;
}

function sign(x) {
    return (x > 0.0 ? 1 : (x < 0.0 ? -1 : 0));
}

function action(key, value, dt)
{
    if (key == AAuxb1 && value == 0) {
        this.automaticTransmission = !this.automaticTransmission;
        this.log_inf("Automatic transmission " + (this.automaticTransmission ? "enabled" : "disabled"));
    }

    if (value == 1 && !this.automaticTransmission) {
        switch(key) {
            case AShiftUp:
                this.shiftUp();
                break;
            case AShiftDown:
                this.shiftDown();
                break;
            default:
                break;
        }
    }
}

function select_gear(gear)
{
    var i = this.gear.index;
    this.gear = gear;
    this.log_inf("gear " + i + " => " + this.gear.index);
}

function shift_up()
{
    var i = this.gear.index;
    if (this.gear.next) {
        this.selectGear(this.gear.next);
    } else if (i == 0) {
        this.selectGear(this.forwardGears[0]);
    } else if (i == -1) {
        this.selectGear(this.neutroGear);
    }
}

function shift_down()
{
    var i = this.gear.index;
    if (this.gear.prev) {
        this.selectGear(this.gear.prev);
    } else if (i == 0) {
        this.selectGear(this.reverseGears[0]);
    } else if (i == 1) {
        this.selectGear(this.neutroGear);
    }
}

function die()
{
    this.started = false;
}

function automatic_transmission(engine)
{
    if (this.engineRPM < 10 && this.gear.index != 0) {
        this.gear = this.neutroGear;
        this.direction = 0;
        this.selectGear(this.neutroGear);
    }
    if (engine != 0.0) {
        if (sign(engine) != this.direction) {
            this.direction = sign(engine);
            if (this.direction == 1.0) {
                this.selectGear(this.forwardGears[0]);
            } else if (this.direction == -1.0) {
                this.selectGear(this.reverseGears[0]);
            }
        }

        if (this.engineRPM > this.gear.shiftUp && this.gear.next) {
            this.shiftUp();
        } else if (this.engineRPM < this.gear.shiftDown && this.gear.prev) {
            this.shiftDown();
        }
    }
}

function animate()
{
    this.animate_wheels();
}

//invoked each frame to handle the inputs and animate the model
function update_frame(dt, engine, brake, steering) {
    steering *= 0.6;
    this.steer(-2, steering);

    var wheelsRpm = this.max_rpm();
    if (sign(this.speed()) != sign(this.gear.index) && this.gear.index != 0) {
        wheelsRpm = 0;
    }

    if (this.automaticTransmission) {
        this.updateAutomaticTransmission(engine);
    }
    if (engine < 0) {
        engine = -engine;
    }

    var clutched = this.clutchState == 1 && this.gear.index != 0;

    var clutchRPM = this.minimumRPM + 2000;
    if (this.automaticClutch) {
        if (clutched && this.engineRPM < this.minimumRPM) {
            this.clutchState = 0;
        } else if (!clutched && this.engineRPM > clutchRPM) {
            this.clutchState = 1;
        }
        clutched = this.clutchState == 1 && this.gear.index != 0;
    }

    var w = wheelsRpm * this.gear.ratio * this.differentialRatio;
    if (clutched) {
        this.clutch = (w > this.minimumRPM ? this.minimumRPM : w) / this.minimumRPM;

        // This makes an horizontal S-like shape. (mirrored, like Z)
        var f = this.clutch * 2;
        if (f < 0.5) {
            this.clutch = -(f * f * f * f - 1) / 5;
        } else {
            f = f - 1;
            this.clutch = (f * f * f * f)  + 0.2;
        }
        this.clutch += 0.2;

        var r = this.engineRPM / clutchRPM;
        this.clutch *= (r > 1 ? 1 : (r < 0 ? 0 : r));

        if (this.clutch > 1) {
            this.clutch = 1;
        }
    } else if (!clutched) {
        this.clutch = 0;
    }

    this.appliedTorque = 0;
    if (this.starting) {
        if (this.engineRPM > this.minimumRPM) {
            this.starting = false;
            this.started = true;
        } else {
            this.appliedTorque = 100 * (1 - this.engineRPM / this.minimumRPM);
        }
    }

    var oldRPM = this.engineRPM;

    if (this.gear.index != 0) {
        this.engineRPM = this.engineRPM * (1 - this.clutch) + wheelsRpm * this.clutch * this.gear.ratio * this.differentialRatio;
    }

    var engineStarted = this.started;
    if (engineStarted || this.starting) {
        if (this.engineRPM < this.minimumRPM && engine < this.minimum) {
            engine = this.minimum;
        }
        if (this.speedLimiter < 0 || Math.abs(this.speed()) < this.speedLimiter) {
            this.appliedTorque += engine * this.torque(this.engineRPM);
        }
    }

    var friction = 0.1;
    this.appliedTorque -= sign(this.engineRPM) * this.maxPowerTP.torque * this.engineBrakeCoefficient *
                          (friction + (1.0 - friction) * this.engineRPM / this.maxRPM);

    this.engineRPM = this.engineRPM + this.appliedTorque * dt / this.engineInertia;
    if (oldRPM < 300) {
        this.die();
    }

    var tq = this.appliedTorque + this.engineInertia * (oldRPM - this.engineRPM) / dt;
    var force = tq * this.clutch * this.gear.ratio * this.differentialRatio * this.efficiency / this.wheelRadius;
    if (this.gear.index < 0) {
        force = -force;
    }

    this.wheel_force(2, force / 2);
    this.wheel_force(3, force / 2);

    brake *= this.breakingForce;
    this.wheel_brake(-1, brake);

    this.animate();

    if (this.gear.index == 0 && (!this.snd.is_playing(0) || this.soundId != 1)) {
        this.snd.stop(0);
        this.snd.play(0, 1, true, false);
        this.soundId = 1;
    } else if (this.gear.index != 0 && engine != 1 && (!this.snd.is_playing(0) || this.soundId != 2)) { //idle
        this.snd.stop(0);
        this.snd.play(0, 2, true, false);
        this.soundId = 2;
    } else if (this.gear.index != 0 && engine == 1 && (!this.snd.is_playing(0) || this.soundId != 3)) { //throttle
        this.snd.stop(0);
        this.snd.play(0, 3, true, false);
        this.soundId = 3;
    }

    var pitch = this.pitchMultiplier * (this.engineRPM - this.minimumRPM) / this.maxRPM;
    this.snd.set_pitch(0, pitch + this.basepitch[this.soundId]);
    var g = this.engineRPM / this.minimumRPM;
    this.snd.set_gain(0, Math.min(g * g * g, 1.0));
}
Logged
ResidualVM 0.1.1 is OUT! www.residualvm.org

M7

  • Hero Member
  • *****
  • Posts: 736
  • newbie
Re: Vehicle script [version 1.2.1]
« Reply #18 on: May 09, 2013, 09:40:55 am »

Yep works perferctly now. Thanks!



Logged

ZeosPantera

  • ||>>-Z-<<||
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2520
  • #1 Outerra Fan Boy
    • My Youtube
Re: Vehicle script [version 1.2.1]
« Reply #19 on: May 09, 2013, 01:19:42 pm »

I think a test vehicle needs to be modeled that has an external wheel or fan that represents the "Engine RPM" and then you could watch how it reacts to clutching and power loss etc.

Maybe go full-retard and import something like this::




NO FREAKIN WAY.. http://sketchup.google.com/3dwarehouse/cldetails?mid=29422801b7c529217109178e924a3a02&ct=mdcc&prevstart=0  Anyone feel like helping me with a little project?

Damn.. colz::mesh::optimize_mesh_indices@colz_mesh.cpp(641) Mesh "@0"cannot have more than 65535 vertices! (src mesh vertex count: 23077)
« Last Edit: May 09, 2013, 03:05:24 pm by ZeosPantera »
Logged
"Fear accompanies the possibility of death, Calm shepherds its certainty" - General Ka Dargo

M7

  • Hero Member
  • *****
  • Posts: 736
  • newbie
Re: Vehicle script [version 1.2.1]
« Reply #20 on: May 09, 2013, 04:00:39 pm »

Ill make a quick import of the super car. It does look very cool, so much stuff to animate. it would look bassass if every moving part were animated.

wow this thing is quite complex, sketchup takes forever just to explode all groups/componants
« Last Edit: May 09, 2013, 04:11:56 pm by M7 »
Logged

M7

  • Hero Member
  • *****
  • Posts: 736
  • newbie
Re: Vehicle script [version 1.2.1]
« Reply #21 on: May 09, 2013, 10:29:12 pm »

Sorry the model has too many vertices , more than 65535 says the error message. which seems to be the limit  :'(

edit: Ah ok you beat me to it
« Last Edit: May 09, 2013, 10:33:23 pm by M7 »
Logged

ZeosPantera

  • ||>>-Z-<<||
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2520
  • #1 Outerra Fan Boy
    • My Youtube
Re: Vehicle script [version 1.2.1]
« Reply #22 on: May 09, 2013, 11:41:54 pm »

It would need some work done to fix that. All those damn crown nuts.
Logged
"Fear accompanies the possibility of death, Calm shepherds its certainty" - General Ka Dargo

krz9000

  • Member
  • **
  • Posts: 62
Re: Vehicle script [version 1.2.1]
« Reply #23 on: May 10, 2013, 07:45:55 am »

lego_technic_8880_supercar.fbx

https://docs.google.com/file/d/0ByUs2QvLmkw4VTZrX2Nvc3JPM1E/edit?usp=sharing


i cleaned up the lego car a bit. normals are all nice now, made some basic uvs and started to group dynamic parts. im going to update the file every now and then
Logged

ZeosPantera

  • ||>>-Z-<<||
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2520
  • #1 Outerra Fan Boy
    • My Youtube
Re: Vehicle script [version 1.2.1]
« Reply #24 on: May 10, 2013, 09:33:38 am »

Quick question. What is an FBX? (Cancel that I looked it up)

Soooooo I need that program to get it converted to work in OT?

Logged
"Fear accompanies the possibility of death, Calm shepherds its certainty" - General Ka Dargo

mLichy

  • Full Member
  • ***
  • Posts: 104
  • newbie
Re: Vehicle script [version 1.2.1]
« Reply #25 on: May 10, 2013, 09:59:21 am »

Auto desk products will open it. Maybe others.
Logged

PytonPago

  • Hero Member
  • *****
  • Posts: 2284
  • It´s way too complex, dont let me try to explain !
Re: Vehicle script [version 1.2.1]
« Reply #26 on: May 10, 2013, 04:45:42 pm »

I think a test vehicle needs to be modeled that has an external wheel or fan that represents the "Engine RPM" and then you could watch how it reacts to clutching and power loss etc.

 ... give me time to Monday and i give you the engine fan  ;D  And as for the Lego - i hope you dont plan to implement that in a in-game building fashion, hard to build in a carpet, no need to fight some mouse for it.  ;D :D

Quote from: M7
Sorry the model has too many vertices , more than 65535 says the error message. which seems to be the limit

Just found this line :o  ...  dont like that number  :-\
Logged
We are still undeveloped as long as we don´t realize, that all our science is still descriptive, and than beyond that description lies a whole new world we just haven´t even started to fully understand.

giucam

  • Full Member
  • ***
  • Posts: 171
  • It's an ugly pile of bones... like me.
Re: Vehicle script [version 1.2.1]
« Reply #27 on: May 10, 2013, 04:52:33 pm »

That Lego model is wonderful, but i think a HUD showing the RPM may be more effective ;)

Quote
Quote from: M7
Sorry the model has too many vertices , more than 65535 says the error message. which seems to be the limit

Just found this line   ...  dont like that number 

Actually, meshes have the 65535 limit, not models. Models can have more than one mesh.
Logged
ResidualVM 0.1.1 is OUT! www.residualvm.org

M7

  • Hero Member
  • *****
  • Posts: 736
  • newbie
Re: Vehicle script [version 1.2.1]
« Reply #28 on: May 10, 2013, 07:43:18 pm »

Well i gave the lego car another go. This time i didn't explode the groups/components and it did import fine.

https://docs.google.com/file/d/0B96RrTcNJsI2ZFgxMDczZVU5Vnc/edit?usp=sharing
Logged

ZeosPantera

  • ||>>-Z-<<||
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2520
  • #1 Outerra Fan Boy
    • My Youtube
Re: Vehicle script [version 1.2.1]
« Reply #29 on: May 10, 2013, 11:30:19 pm »

Well i gave the lego car another go. This time i didn't explode the groups/components and it did import fine.

https://docs.google.com/file/d/0B96RrTcNJsI2ZFgxMDczZVU5Vnc/edit?usp=sharing

Love is a over used concept. But I love you man.
Logged
"Fear accompanies the possibility of death, Calm shepherds its certainty" - General Ka Dargo
Pages: 1 [2] 3 4 ... 8