help with weapons on vehicles
by Roger Smith · in General Discussion · 04/20/2003 (1:21 am) · 22 replies
I need help with getting a vehicle weapon script made. Could somebody please post an example thats working with HEAD and would fundtion with a standard weapon scene? I would greatly appreciatte it.
#2
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2601
04/20/2003 (1:29 am)
Right here:www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2601
#3
04/20/2003 (1:57 am)
Please no more posts linking to deathcar's script. It isnt working correctly.
#4
Although, you will need to merge the new car datablock and onAdd() function. The weapon mounting code is pretty much universal throughout torque.
I guess what you are saying is you need someone to write that for you?
Give me a little bit, I'll give you an example of mine.
04/20/2003 (3:11 am)
Works great for me! :)Although, you will need to merge the new car datablock and onAdd() function. The weapon mounting code is pretty much universal throughout torque.
I guess what you are saying is you need someone to write that for you?
Give me a little bit, I'll give you an example of mine.
#5
Not too difficult really, I hope I got all the changes out from my vehicle stuff though.
Let me know if there is a problem with this.
04/20/2003 (3:17 am)
datablock WheeledVehicleData(DefaultCar)
{
category = "Vehicles";
shapeFile = "~/path/to/your/model/";
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
// 3rd person camera settings
cameraRoll = true; // 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 -0.2"; // Center of mass for rigid body
massBox = "0 0 0"; // 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
// Engine
engineTorque = 8000; // Engine power
engineBrake = 600; // Braking when throttle is 0
brakeTorque = 2000; // When brakes are applied
maxWheelSpeed = 30; // Engine scale by current speed / max speed
// Energy
maxEnergy = 100;
jetForce = 3000;
minJetEnergy = 30;
jetEnergyDrain = 2;
// Sounds
engineSound = StryderIdleEngineSound;
// squealSound = ScoutSound;
// softImpactSound = SoftImpactSound;
// hardImpactSound = HardImpactSound;
// wheelImpactSound = WheelImpactSound;
// explosion = VehicleExplosion;
};
datablock WheeledVehicleTire(DefaultCarTire)
{
// Tires act as Suspensions and generate lateral and longitudinal
// forces to move the vehicle. These distortion/Suspension forces
// are what convert wheel angular velocity into forces that
// act on the rigid body.
shapeFile = "~/path/to/your/model/";
staticFriction = 6.0;
kineticFriction = 1;
// Spring that generates lateral tire forces
lateralForce = 6000;
lateralDamping = 400;
lateralRelaxation = 1;
// Spring that generates longitudinal tire forces
longitudinalForce = 6000;
longitudinalDamping = 400;
longitudinalRelaxation = 1;
};
datablock WheeledVehicleSpring(DefaultCarSpring)
{
// Wheel suspension properties
length = 0.85; // Suspension travel
force = 2000; // Spring force
damping = 400; // Spring damping
antiSwayForce = 2; // Lateral anti-sway force
};
function DefaultCar::onAdd(%this,%obj)
{
Parent::onAdd(%this,%obj);
// Setup the car with some defaults tires & springs
for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
%obj.setWheelTire(%i,DefaultCarTire);
%obj.setWheelSpring(%i,DefaultCarSpring);
%obj.setWheelPowered(%i,false);
}
// Steer front tires
%obj.setWheelSteering(2,1);
%obj.setWheelSteering(3,1);
// Only power the two rear wheels...
%obj.setWheelPowered(0,true);
%obj.setWheelPowered(1,true);
// THIS IS WHERE YOU MOUNT YOUR WEAPON
%obj.mountImage(_YOUR_WEAPON_HERE_, _MOUNT_NODE_HERE_);
}
function DefaultCar::onDamage(%this, %obj)
{
Parent::onDamage(%this, %obj);
}Not too difficult really, I hope I got all the changes out from my vehicle stuff though.
Let me know if there is a problem with this.
#6
example:
The crossbow mounted on a vehicle how would the code to trigger and fire it aswell as handle ammo etc?
04/20/2003 (3:31 am)
I do not need the vehicle datablocks or mount information, Just the weapon code. The code that handles the triggering and firing and animations etc. The weapon is mounted and firing but not correctly and consistently. I need the code for the weapon not the vehicle.example:
The crossbow mounted on a vehicle how would the code to trigger and fire it aswell as handle ammo etc?
#7
04/20/2003 (6:36 am)
Read the example before discarding it,The triggering code is all in theredatablock ShapeBaseImageData(CarbowImage)
{
// Basic Item properties
shapeFile = "~/data/shapes/car/carbow.dts";
emap = true;
// Specify mount point & offset for 3rd person, and eye offset
// for first person rendering.
mountPoint = 0;
offset = "0 0 0";
correctMuzzleVector = false;
className = "WeaponImage";
projectile = CrossbowProjectile;
projectileType = Projectile;
fireTimeout = 300;
// Initial start up state
stateName[0] = "Preactivate";
stateTransitionOnLoaded[0] = "Activate";
stateTransitionOnNoAmmo[0] = "Activate";
// Activating the gun. Called when the weapon is first
// mounted and there is ammo.
stateName[1] = "Activate";
stateTransitionOnTimeout[1] = "Ready";
stateTimeoutValue[1] = 0.6;
stateSequence[1] = "Activate";
// Ready to fire, just waiting for the trigger
stateName[2] = "Ready";
stateTransitionOnNoAmmo[2] = "Activate";
stateTransitionOnTriggerDown[2] = "Fire";
// Fire the weapon. Calls the fire script which does
// the actual work.
stateName[3] = "Fire";
stateTransitionOnTimeout[3] = "Reload";
stateTimeoutValue[3] = 0.2;
stateFire[3] = true;
stateRecoil[3] = LightRecoil;
stateAllowImageChange[3] = false;
stateSequence[3] = "Fire";
stateScript[3] = "onFire";
// Play the relead animation, and transition into
stateName[4] = "Reload";
stateTransitionOnNoAmmo[4] = "Activate";
stateTransitionOnTimeout[4] = "Ready";
stateTimeoutValue[4] = 0.8;
stateAllowImageChange[4] = false;
stateSequence[4] = "Reload";
stateEjectShell[4] = true;
// No ammo in the weapon, just idle until something
// shows up. Play the dry fire sound if the trigger is
// pulled.
stateName[5] = "Activate";
stateTransitionOnAmmo[5] = "Reload";
stateSequence[5] = "Activate";
stateTransitionOnTriggerDown[5] = "DryFire";
// No ammo dry fire
stateName[6] = "DryFire";
stateTimeoutValue[6] = 1.0;
stateTransitionOnTimeout[6] = "Activate";
};
datablock ShapeBaseImageData(Carbow2Image : CarbowImage)
{
mountPoint = 1;
};
function DefaultCar::onTrigger(%data, %obj, %trigger, %state)
{
// data = datablock
// obj = object number
// trigger = 0 for "fire", 1 for "jump", 3 for "thrust"
// state = 1 for firing, 0 for not firing
if(%trigger == 0)
{
switch (%state) {
case 0:
%obj.fireWeapon = false;
%obj.setImageTrigger(0, false);
%obj.setImageTrigger(1, false);
case 1:
%obj.fireWeapon = true;
if(%obj.nextWeaponFire == 0) {
%obj.setImageTrigger(0, true);
%obj.setImageTrigger(1, false);
}
else {
%obj.setImageTrigger(0, false);
%obj.setImageTrigger(1, true);
}
}
}
}
function CarbowImage::onFire(%data,%obj,%slot)
{
Parent::onFire(%data,%obj,%slot);
%obj.nextWeaponFire = 1;
schedule(%data.fireTimeout, 0, "fireNextGun", %obj);
}
function Carbow2Image::onFire(%data,%obj,%slot)
{
Parent::onFire(%data,%obj,%slot);
%obj.nextWeaponFire = 0;
schedule(%data.fireTimeout, 0, "fireNextGun", %obj);
}
function CarbowImage::onTriggerDown(%this, %obj, %slot)
{
}
function CarbowImage::onTriggerUp(%this, %obj, %slot)
{
}
function fireNextGun(%obj)
{
if(%obj.fireWeapon)
{
if(%obj.nextWeaponFire == 0)
{
%obj.setImageTrigger(0, true);
%obj.setImageTrigger(1, false);
}
else
{
%obj.setImageTrigger(0, false);
%obj.setImageTrigger(1, true);
}
}
else
{
%obj.setImageTrigger(0, false);
%obj.setImageTrigger(1, false);
}
}
function ShapeBaseImageData::onFire(%data, %obj, %slot)
{
%projectile = %data.projectile;
%muzzleVector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor));
%vehicle = 0;
%p = new (%data.projectileType)() {
dataBlock = %data.projectile;
initialVelocity = %muzzleVelocity;
initialDirection = %obj.getMuzzleVector(%slot);
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
vehicleObject = %vehicle;
};
if (isObject(%obj.lastProjectile) && %obj.deleteLastProjectile)
%obj.lastProjectile.delete();
%obj.lastProjectile = %p;
%obj.deleteLastProjectile = %data.deleteLastProjectile;
MissionCleanup.add(%p);
return %p;
}
#8
04/20/2003 (6:47 am)
Please dont post the deathcar script. just delete both those snippets dont waste GG's hard drive re-posting deathcar over and over.
#9
People are only tryng to help you.
04/20/2003 (10:00 am)
Quote: . . . Just the weapon code. The code that handles the triggering and firing and animations etc.before I erase it I would be wise to look at CarbowImage::onFire
Quote:The crossbow mounted on a vehicle how would the code to trigger and fire it aswell as handle ammo etc?datablock ShapeBaseImageData(CarbowImage) and function ShapeBaseImageData::onFire(%data, %obj, %slot) notice the ammo never is decreased.
Quote:Please dont post the deathcar script. just delete both those snippets dont waste GG's hard drive re-posting deathcar over and over.
People are only tryng to help you.
#10
just because you can't get it to work doesnt mean that the script isn't working at all ...
04/20/2003 (10:38 am)
LOL, Tim, if you dont want help, dont post :Pjust because you can't get it to work doesnt mean that the script isn't working at all ...
#11
The deathcar script i hacked apart almost kinda works so im not really wanting complicated advice on how to hack deathcar again. just an example vehicle weapon script that isnt deathcar.cs and dosnt have code for 3 weapons jumps speed boosts etc. I could use the deathcar.cs but i dont want a deathcar, just a weapon on a vehicle. i know how to mount the weapon on the vehicle model.
04/20/2003 (11:12 am)
no, its just ive heard look at deathcar so many times, i was afraid anthony or someone else would come back and post it again only different portions :/ I am not a programmer so i just kinda need as generic a weapon script as possible. The deathcar script is way to tweaked i have no idea whats going on in it. All i need is a generic vehicle weapon script that isnt deathcar.csThe deathcar script i hacked apart almost kinda works so im not really wanting complicated advice on how to hack deathcar again. just an example vehicle weapon script that isnt deathcar.cs and dosnt have code for 3 weapons jumps speed boosts etc. I could use the deathcar.cs but i dont want a deathcar, just a weapon on a vehicle. i know how to mount the weapon on the vehicle model.
#12
And this discussion should really be in the appropriate forum
04/20/2003 (1:22 pm)
Ummm... deathcar IS a generic exampleAnd this discussion should really be in the appropriate forum
#13
04/20/2003 (11:51 pm)
Please i dont want to use or debate the qualities of deathcar.cs I do not want the vehicle to have the deathcar scripts becuase they dont make sense or work correctly. I need a vehicle weapon script that isnt deathcar.cs and dosnt have jump/boost and 3 weapons. I need a vechicle weapon script that isnt deathcar.cs
#14
04/21/2003 (12:23 am)
Deathcar.cs does not have 3 weapons, nor does it have jump or boost. If your copy did have those it was not added by me.
#15
maxInv[BulletAmmo] = 20;
maxInv[HealthKit] = 1;
maxInv[RifleAmmo] = 100;
maxInv[CrossbowAmmo] = 100;
maxInv[Crossbow] = 1;
maxInv[Rifle] = 1;
Then I took this from fps.cs:
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,100);
and out it in the CreatePlayer function of racing.cs and Wham-o! Instant crossbow for the buggy.
01/25/2004 (12:31 pm)
I know this is an old thread, but I was able to take the following from player.cs and put it in the WheeledVehicleData(DefaultCar)Datablock in car.cs:maxInv[BulletAmmo] = 20;
maxInv[HealthKit] = 1;
maxInv[RifleAmmo] = 100;
maxInv[CrossbowAmmo] = 100;
maxInv[Crossbow] = 1;
maxInv[Rifle] = 1;
Then I took this from fps.cs:
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,100);
and out it in the CreatePlayer function of racing.cs and Wham-o! Instant crossbow for the buggy.
#16
HEY WAIT! N/M it works it fires!! If anybody wants to get the deathcar.zip with all the changes following these forums, let me know (I know how hard it can be.)
Yay! and now, on with the game! :)
05/18/2004 (6:17 pm)
Hey David - when you tried that, did it fire? Mine doesn't. I'm trying the deathcar thing too, trying to get either car to shoot. HEY WAIT! N/M it works it fires!! If anybody wants to get the deathcar.zip with all the changes following these forums, let me know (I know how hard it can be.)
Yay! and now, on with the game! :)
#17
I can understand your frustration after a day of debugging this is what i've found.
1. Anthony the deathcar code you posted is FLAWED. State 1 and 5 are both named "Activate". how does the engine differentiate which one you want to go to. Tim draw out a state diagram it'll become aparent where the state paths are supposed to go. Name state 5 something else and alter the ready state from going to activate to your renamed state. Have a closer look at the crossbow states in stater.fps for a cleaner version.
2. Be careful with a few states, Torque under certain condition will IMMEDIATELY jump to other states bypassing the state you think it's supposed to go to. Eg. State 2 "Ready" will never reach the Fire state IF there isn''t any ammo. It will is it immediately jump to "Activate" if that is the case. I don't completely agree with GG's way of implementing this but you can't argue with increase speed by skipping X state transitions and going to something that is needed.
*let me correct number 2. above, it does in fact reach state 2 "ready" but as soon as it does it will jump to the activate state becuase there is no ammo. Meaning you will NEVER be able to transition to the fire state.
Guys if your going to post code can you please make you TEST it first. It doesn't have to be correct but at least run it for yourselves, i'm sure if someone ran the above state code they would of noticed this dual state naming issue.
Tim please do not disrespect people who try to help you. No matter the circumstance it's darn right rude. I suggest you learn to code and debug it's the only way you'll be able to find problems like this.
Anyway I hope that helps
07/30/2004 (11:51 pm)
Tim,I can understand your frustration after a day of debugging this is what i've found.
1. Anthony the deathcar code you posted is FLAWED. State 1 and 5 are both named "Activate". how does the engine differentiate which one you want to go to. Tim draw out a state diagram it'll become aparent where the state paths are supposed to go. Name state 5 something else and alter the ready state from going to activate to your renamed state. Have a closer look at the crossbow states in stater.fps for a cleaner version.
2. Be careful with a few states, Torque under certain condition will IMMEDIATELY jump to other states bypassing the state you think it's supposed to go to. Eg. State 2 "Ready" will never reach the Fire state IF there isn''t any ammo. It will is it immediately jump to "Activate" if that is the case. I don't completely agree with GG's way of implementing this but you can't argue with increase speed by skipping X state transitions and going to something that is needed.
*let me correct number 2. above, it does in fact reach state 2 "ready" but as soon as it does it will jump to the activate state becuase there is no ammo. Meaning you will NEVER be able to transition to the fire state.
Guys if your going to post code can you please make you TEST it first. It doesn't have to be correct but at least run it for yourselves, i'm sure if someone ran the above state code they would of noticed this dual state naming issue.
Tim please do not disrespect people who try to help you. No matter the circumstance it's darn right rude. I suggest you learn to code and debug it's the only way you'll be able to find problems like this.
Anyway I hope that helps
#18
07/31/2004 (6:35 am)
I got deathcar to work fine as a vehicle and a weapon, my only issue I had seemed minor; I had unlimited ammo!, which is not what I wanted. I included the weapons entire script from when I tested it as a hand held weapon and commented that one out after seeing it inside the vehicle as the example showed. Nothing I could fiddle with in player's inventory would change my ability to reload it, I wanted to have my player be able to inventory ammo and be able to ues it when on the vehicle. Is that the way? or is it the same to give the vehicle the inventory as in the above example? I mean, will the vehicle have to do the actual 'pickup/inventory' of the item[ammo]?
#19
As for if it had been tested, yes I tested it several times and it worked fine, 2 1/2 years ago when it was written and posted. And it should still work fine, although the 5th state will never be used. The state system is an array so the first Activate state declared will be the one that is used every time, the second one will be ignored. And yes I wrote the stateSequence to call to Activate as the deathcar demo had unlimited ammo, there was never a call to decrease ammo.
This is how you expected the StateSequence:
07/31/2004 (1:16 pm)
The deathcar resource is VERY old and was done in a short time.As for if it had been tested, yes I tested it several times and it worked fine, 2 1/2 years ago when it was written and posted. And it should still work fine, although the 5th state will never be used. The state system is an array so the first Activate state declared will be the one that is used every time, the second one will be ignored. And yes I wrote the stateSequence to call to Activate as the deathcar demo had unlimited ammo, there was never a call to decrease ammo.
This is how you expected the StateSequence:
// Initial start up state stateName[0] = "Preactivate"; stateTransitionOnLoaded[0] = "Activate"; stateTransitionOnNoAmmo[0] = "NoAmmo"; // Activating the gun. Called when the weapon is first // mounted and there is ammo. stateName[1] = "Activate"; stateTransitionOnTimeout[1] = "Ready"; stateTimeoutValue[1] = 0.6; stateSequence[1] = "Activate"; // Ready to fire, just waiting for the trigger stateName[2] = "Ready"; stateTransitionOnNoAmmo[2] = "NoAmmo"; stateTransitionOnTriggerDown[2] = "Fire"; // Fire the weapon. Calls the fire script which does // the actual work. stateName[3] = "Fire"; stateTransitionOnTimeout[3] = "Reload"; stateTimeoutValue[3] = 0.2; stateFire[3] = true; stateRecoil[3] = LightRecoil; stateAllowImageChange[3] = false; stateSequence[3] = "Fire"; stateScript[3] = "onFire"; // Play the relead animation, and transition into stateName[4] = "Reload"; stateTransitionOnNoAmmo[4] = "NoAmmo"; stateTransitionOnTimeout[4] = "Ready"; stateTimeoutValue[4] = 0.8; stateAllowImageChange[4] = false; stateSequence[4] = "Reload"; stateEjectShell[4] = true; // No ammo in the weapon, just idle until something // shows up. Play the dry fire sound if the trigger is // pulled. stateName[5] = "NoAmmo"; stateTransitionOnAmmo[5] = "Reload"; stateSequence[5] = "NoAmmo"; stateTransitionOnTriggerDown[5] = "DryFire"; // No ammo dry fire stateName[6] = "DryFire"; stateTimeoutValue[6] = 1.0; stateTransitionOnTimeout[6] = "NoAmmo";
#20
thanks..
08/27/2004 (7:41 am)
@andrew: can i take pick of the deathcar.zip? is it the most updated version?thanks..
Torque Owner Anthony McCrary