Torque Script Bike
by Brian Jansen · 03/17/2006 (6:57 pm) · 26 comments
Ok I got an email from James Laker Requesting how to get the code I posted about in an earlier resource. So First I warn you this was written in 1.2 but it still should work.
The model needs only 2 hub nodes the front should be called hub0 and the back hub2 and thats it with the model changes.
And now for the code:
The model needs only 2 hub nodes the front should be called hub0 and the back hub2 and thats it with the model changes.
And now for the code:
//----------------------------------------------------------------------------
datablock WheeledVehicleTire(aiorbikeTire)
{
// Tires act as springs and generate lateral and longitudinal
// forces to move the vehicle. These distortion/spring forces
// are what convert wheel angular velocity into forces that
// act on the rigid body.
shapeFile = "~/data/shapes/vehicles/bike/wheel.dts";
staticFriction = 4;
kineticFriction = 1.25;
// Spring that generates lateral tire forces
lateralForce = 18000;
lateralDamping = 4000;
lateralRelaxation = 1;
// Spring that generates longitudinal tire forces
longitudinalForce = 18000;
longitudinalDamping = 4000;
longitudinalRelaxation = 1;
};
datablock WheeledVehicleSpring(aiorbikeSpring)
{
// Wheel suspension properties
length = 0.15; // Suspension travel
force = 3000; // Spring force
damping = 600; // Spring damping
antiSwayForce = 3; // Lateral anti-sway force
};
datablock WheeledVehicleData(aiorbike)
{
category = "Vehicles";
shapeFile = "~/data/shapes/vehicles/bike/legobike.dts";
emap = true;
maxDamage = 1.0;
destroyedLevel = 0.5;
maxSteeringAngle = 0.785; // Maximum steering angle, should match animation
tireEmitter = TireEmitter; // All the tires use the same dust emitter
maxDamage = 50.40;
destroyedLevel = 50.40
// 3rd person camera settings
cameraRoll = false; // Roll the camera with the vehicle
cameraMaxDist = 6; // Far distance from vehicle
cameraOffset = 1.5; // Vertical offset from camera mount point
cameraLag = 0.1; // Velocity lag of camera
cameraDecay = 0.75; // Decay per sec. rate of velocity lag
// Rigid Body
mass = 200;
massCenter = "0 -0.5 0"; // Center of mass for rigid body
massBox = "10 5 1"; // Size of box used for moment of inertia,
// if zero it defaults to object bounding box
drag = 0.6; // Drag coefficient
bodyFriction = 0.6;
bodyRestitution = 0.4;
minImpactSpeed = 5; // Impacts over this invoke the script callback
softImpactSpeed = 5; // Play SoftImpact Sound
hardImpactSpeed = 15; // Play HardImpact Sound
integration = 4; // Physics integration: TickSec/Rate
collisionTol = 0.1; // Collision distance tolerance
contactTol = 0.1; // Contact velocity tolerance
// Ground Impact Damage (uses DamageType::Ground)
//minImpactSpeed = 10; // If hit ground at speed above this then it's an impact. Meters/second
speedDamageScale = 0.06;
// Object Impact Damage (uses DamageType::Impact)
collDamageThresholdVel = 23.0;
collDamageMultiplier = 0.02
// Engine
engineTorque = 4000; // Engine power
engineBrake = 600; // Braking when throttle is 0
brakeTorque = 8000; // When brakes are applied
maxWheelSpeed = 40; // Engine scale by current speed / max speed
// Energy
maxEnergy = 100;
jetForce = 3000;
minJetEnergy = 30;
jetEnergyDrain = 2;
// Sounds
// jetSound = ScoutThrustSound;
// engineSound = aiorbikeEngineSound;
// squealSound = ScoutSquealSound;
// softImpactSound = SoftImpactSound;
// hardImpactSound = HardImpactSound;
// wheelImpactSound = WheelImpactSound;
explosion = VehicleExplosion;
maxMountSpeed = 0.1;
mountDelay = 2;
dismountDelay = 1;
stationaryThreshold = 0.5;
maxDismountSpeed = 0.1;
numMountPoints = 1;
mountable = true;
mountPose[0] = "Sitting";
mountPointTransform[0] = "0 0 0 0 0 1 0";
isProtectedMountPoint[0] = false;
};
//-----------------------------------------------------------------------------
function aiorbike::onAdd(%this,%obj)
{
// Setup the car with some defaults tires & springs
for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
%obj.setWheelTire(%i,aiorbikeTire);
%obj.setWheelSpring(%i,aiorbikeSpring);
%obj.setWheelPowered(%i,false);
}
// Steer front tires
%obj.setWheelSteering(0,2);
%obj.setWheelSteering(2,2);
// Only power the two rear wheels...
%obj.setWheelPowered(0,true);
%obj.setWheelPowered(1,true);
%obj.setWheelPowered(2,true);
%obj.setWheelPowered(3,true);
// Enable Mount Points
%obj.mountable = true;
}As you can see the 2 wheels that are not on the vehicle are still being powered which for some reason makes this whole thing work. If you have any questions and or comments please post here.
#22
eg... mDot does what? and mFab?
02/27/2006 (10:18 pm)
John... I know it's just an easy fix... I've really messed with all the script values, as I'm clueless when it comes to physics... Screw the physics... I don't even know what all those things mean, when trying to follow the updateforces function... :)eg... mDot does what? and mFab?
#23
i am a firm devotee of the 'scripting only', school of thought, (don't laugh) and i luv it when i see stuff like this...
--Mike
03/19/2006 (5:15 am)
this is great stuff guys... reading this thread i'm really impressed... i think you've done a great job here.i am a firm devotee of the 'scripting only', school of thought, (don't laugh) and i luv it when i see stuff like this...
--Mike
#24
03/25/2006 (8:08 am)
Guys, an easy way to make it tilt more realistically is to make the mass center have a low Z value, such as 0 0 -0.5. I'm not completely sure, but the way Torque makes vehicles tilt is by moving the mass center in the opposite direction when turning. Therefore, if the center is below the wheel nodes, the vehicle will tilt the same direction it is turning because the game is treating the mass center as a pendulum. Something you should note is that this works in four-wheeled vehicles as well, and if the center is way below the nodes it'll tilt too much, almost to the point of flipping completely over.
#25
02/10/2008 (9:31 pm)
Does this lean into corners like a real bike or motorcycle would?
#26
02/10/2008 (11:49 pm)
Yep.
Torque Owner John McArthur
I played with the new gyro forces and if the numbers are bigger, it helps a lot, but its still a simple solution, which is what the guy who wrote the 'stupid wheeled tricks' mod said himself. I think fudging masses, antisway, and these forces over time will get it closer to something really useable.
@ Juan
Im not sure I understand Juan. Explain what your trying to do again. Also, you say it crashes. Is there a messagebox that pops up with error? Does the console log display error?