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.
#2
Do you know if there is a way to have a graphical representation of the Massbox?
02/15/2006 (6:39 am)
So the only changed thing is the Massbox?Do you know if there is a way to have a graphical representation of the Massbox?
#3
02/15/2006 (7:57 am)
I am guessing there could if there were engine changes but I suck at C++
#5
02/16/2006 (3:47 am)
#6
02/16/2006 (5:05 am)
#7
My problem at the moment is that when the bike leans into a corner, it does not 'tilt' correctly...
It also feels like the user needs to balance the bike...
02/16/2006 (5:10 am)
Can you highlight in bold what you have changed? :-)My problem at the moment is that when the bike leans into a corner, it does not 'tilt' correctly...
It also feels like the user needs to balance the bike...
#8
02/16/2006 (5:43 am)
#9
02/16/2006 (6:01 am)
#10
when you have the other resource installed...
-- Checking something quickly --
Your bicycle is looking damn fine!!!!
02/16/2006 (6:16 am)
I think you understand that these values:gyroForce = 16000; // Puts force on bike to keep it upright gyroForceDampen = 50000; //Dampens the force to not have too extreme movement leanForce = 12500; //Force on bike when turning
when you have the other resource installed...
-- Checking something quickly --
Your bicycle is looking damn fine!!!!
#11
02/16/2006 (6:28 am)
#12
My onAdd function does the same as yours.
So if your bicycle starts fallen over... How do you start riding?
Sorry... don't quite understand...?
Chat in mail....
02/16/2006 (6:37 am)
Wierd... I also have only 2 wheels... My onAdd function does the same as yours.
So if your bicycle starts fallen over... How do you start riding?
Quote:
How first?
Sorry... don't quite understand...?
Chat in mail....
#13
02/16/2006 (6:42 am)
#14
02/16/2006 (7:27 am)
I've copied the resource to the engine before try to change these values.
#15
02/16/2006 (8:27 am)
#16
02/17/2006 (3:01 am)
#17
02/21/2006 (6:44 am)
Take a look: http://www.garagegames.com/mg/forums/result.thread.php?qt=34604
#18
I'm at trying to catch up to where you guys are at for 2 wheeled vehicles. I used the 'stupid WheeledVehicle tricks' code to include the gyroscoping code. I have the bike placed in the starter.racing track. When I accelerate the controls and actions of the bike are weird. For example, when I turn left, the bike begins to tip over to the left. The gyroscoping slows it down, but then I have to turn the bike direction to the right to correct the tipping to straighten back up. Does this sound similar?
I was going to move on to other things when I saw this thread. Just looking at Brians code sample, I dont see anything out of the ordinary. He changed his massbox and he sets up 4 wheels on his onadd() function when there are only 2 hubs. The mass box was one of the first quick tricks I attempted, but it didnt work well. Does his bike only work on flat surfaces? I wonder.
Im just curious how well your bikes are acting on hills and on turning. Good luck.
John McArthur
02/23/2006 (4:17 pm)
Hi guys.I'm at trying to catch up to where you guys are at for 2 wheeled vehicles. I used the 'stupid WheeledVehicle tricks' code to include the gyroscoping code. I have the bike placed in the starter.racing track. When I accelerate the controls and actions of the bike are weird. For example, when I turn left, the bike begins to tip over to the left. The gyroscoping slows it down, but then I have to turn the bike direction to the right to correct the tipping to straighten back up. Does this sound similar?
I was going to move on to other things when I saw this thread. Just looking at Brians code sample, I dont see anything out of the ordinary. He changed his massbox and he sets up 4 wheels on his onadd() function when there are only 2 hubs. The mass box was one of the first quick tricks I attempted, but it didnt work well. Does his bike only work on flat surfaces? I wonder.
Im just curious how well your bikes are acting on hills and on turning. Good luck.
John McArthur
#19
John... What you are getting is one of quite a few things that needs to be addressed.
It looks like Juan is happy with his results... as he moved on to the AI
For a bike I need/want more... And those small changes just aren't cutting it for me.
You are right about Brians changes... It's just the Massbox and the wheels.
Going back home... Just came to fetch some work :-(
02/24/2006 (1:53 am)
Hi everyone... I've been sick and in Bed (no internet at home)... But i'm back...John... What you are getting is one of quite a few things that needs to be addressed.
It looks like Juan is happy with his results... as he moved on to the AI
For a bike I need/want more... And those small changes just aren't cutting it for me.
You are right about Brians changes... It's just the Massbox and the wheels.
Going back home... Just came to fetch some work :-(
#20
02/24/2006 (2:11 am)

Torque Owner James Laker (BurNinG)
I'll give it a shot in a second.