[Tutorial] Making units use their own weapons in vehicles
Posted: Tue Aug 09, 2011 5:51 pm
Hello and welcome, this tutorial will guide you through the long process of enabling units(the player) to use their own weapons in vehicles. Its completely different from simply adding the line "AnimatesUnitAsTurret", which can be found in the odf parameters and has absolutely no effect.
Allowing units to use their own weapons in vehicles
this functions just like a normal turret except that the units upper body is used as the aimer.
The unit's ammo and weapons arent displayed. The unit aims into the direction the controller aims and when shooting the muzzleflash is also displayed.
The unit is able to use its first primary weapon (with appropriate animation), its first secondary weapon (without animation). It can/has to reload aswell (without animation) and the weaponammo is calculated correctly.
The camera is automatically set to view the unit in 3rdperson as if it would be controlled normally.
The downsides are: the crosshair is displayed below the middle of the screen, even though the unit shoots in the middle. Also, when the vehicle takes off, the camera moves backwards and stays there which makes it pretty hard to aim.
The ai will not use their weapons, theyll simply stand/sit around.
What you will need:
- a vehicle with a hardpoint to which the unit can be attached
- good knowledge of the hierarchies and setup of a vehicle
- very good knowledge of odf-coding
- about half an hour time
So, lets start with this tedius task. It is one of the most complex things you can do with odf-coding so dont be discouraged if it doesnt work on first try and check all your steps from the beginning on to find the problem.
First step: the model
with custom model:
Create a hardpoint called "hp_passenger_1" or alike and place it where the unit will stand. You can rotate it along the y-axis but the more its rotated, the more the aiming will be limited.
without custom model:
You need a hardpoint to attach the unit to, the stock gunship for example already has them.
Open the model with ultimate unwrap 3d(and download the "Star Wars Battlefront MSH" plugin for it, you can choose it in the dropdown menu on the download page.
Now look for hardpoints, they should be called something like "hp_passenger".
Remember their name.
Second step: the odf
Open the vehicles odf and set up a turretslot (flyersection).
Now put this line within the section:
you also have to specify the animation:
this is the default passengeranimation, it doesnt matter that it includes the unit holding something above it because the upperbody animation will be overriden anyway.
A very important part are the turret and unit rotationvalues. these are:
yaw defines the horizontal rotation and pitch the vertical.
and this is where it gets tricky: even though the unit may not be aligned along the z-axis (zero rotation around the y-axis), the camera/turret is. so if the unit is rotated around 90 degrees and you have a yaw limit of "-45 45" the units upper body will only be able to rotate in the region between 45 and 135 degrees. Therefore you should not rotate the hardpoint to which the unit is attached too much.
The next steps are the critical ones and they are rather complex, so i put them in hide-tags:
thats it for the coding. take a deep breath and relax.
Here is an example of the final odf piece of the turretslot:
Now after you have done all the process, save your odf, munge and enjoy shooting with our unit while sitting/standing in vehicles!
and again: if it doesnt work on first try: dont worry! it also took me quite some time to figure all this out.
Maybe you will discover how to position the crosshair in the middle of the screen or prevent the camera from moving away on takeoff! Please post your finding right here in this thread!
Allowing units to use their own weapons in vehicles
this functions just like a normal turret except that the units upper body is used as the aimer.
The unit's ammo and weapons arent displayed. The unit aims into the direction the controller aims and when shooting the muzzleflash is also displayed.
The unit is able to use its first primary weapon (with appropriate animation), its first secondary weapon (without animation). It can/has to reload aswell (without animation) and the weaponammo is calculated correctly.
The camera is automatically set to view the unit in 3rdperson as if it would be controlled normally.
The downsides are: the crosshair is displayed below the middle of the screen, even though the unit shoots in the middle. Also, when the vehicle takes off, the camera moves backwards and stays there which makes it pretty hard to aim.
The ai will not use their weapons, theyll simply stand/sit around.
What you will need:
- a vehicle with a hardpoint to which the unit can be attached
- good knowledge of the hierarchies and setup of a vehicle
- very good knowledge of odf-coding
- about half an hour time
So, lets start with this tedius task. It is one of the most complex things you can do with odf-coding so dont be discouraged if it doesnt work on first try and check all your steps from the beginning on to find the problem.
First step: the model
with custom model:
Create a hardpoint called "hp_passenger_1" or alike and place it where the unit will stand. You can rotate it along the y-axis but the more its rotated, the more the aiming will be limited.
without custom model:
You need a hardpoint to attach the unit to, the stock gunship for example already has them.
Open the model with ultimate unwrap 3d(and download the "Star Wars Battlefront MSH" plugin for it, you can choose it in the dropdown menu on the download page.
Now look for hardpoints, they should be called something like "hp_passenger".
Remember their name.
Second step: the odf
Open the vehicles odf and set up a turretslot (flyersection).
Now put this line within the section:
Code: Select all
PilotPosition = "nameofhardpoint"Code: Select all
PilotAnimation = "standing"A very important part are the turret and unit rotationvalues. these are:
Code: Select all
YawLimits = "-179 90"
PitchLimits = "-35.0 35.0"and this is where it gets tricky: even though the unit may not be aligned along the z-axis (zero rotation around the y-axis), the camera/turret is. so if the unit is rotated around 90 degrees and you have a yaw limit of "-45 45" the units upper body will only be able to rotate in the region between 45 and 135 degrees. Therefore you should not rotate the hardpoint to which the unit is attached too much.
The next steps are the critical ones and they are rather complex, so i put them in hide-tags:
Hidden/Spoiler:
Here is an example of the final odf piece of the turretslot:
Hidden/Spoiler:
and again: if it doesnt work on first try: dont worry! it also took me quite some time to figure all this out.
Maybe you will discover how to position the crosshair in the middle of the screen or prevent the camera from moving away on takeoff! Please post your finding right here in this thread!