[Tutorial] Making units use their own weapons in vehicles

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
DarthD.U.C.K.
Master of the Force
Master of the Force
Posts: 6027
Joined: Wed Sep 27, 2006 11:05 am
Location: Duckburg, Germany

[Tutorial] Making units use their own weapons in vehicles

Post by DarthD.U.C.K. »

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:

Code: Select all

PilotPosition       = "nameofhardpoint"
you also have to specify the animation:

Code: Select all

PilotAnimation      = "standing"
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:

Code: Select all

YawLimits           = "-179 90"
PitchLimits         = "-35.0 35.0"
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:
Hidden/Spoiler:
Add this:
[code]ControlsUnit = "1" [/code]
thats it for the coding. take a deep breath and relax.

Here is an example of the final odf piece of the turretslot:
Hidden/Spoiler:
FLYERSECTION = "TURRET6"

ControlsUnit = "1" //This allows the controller to use the units first rimary and secondary weapons
PilotPosition = "hp_passenger1"
PilotAnimation = "laat_standing_1"

ThirdPersonFOV = 59.5
PitchRate = 0.8
PitchFilter = 2.75
TurnRate = 1.3
TurnFilter = 2.75

YawLimits = "-179 90" //marks both the turretlimits and limits of upperbody movement
PitchLimits = "-35.0 35.0"

PCPitchTurnFactor = "20.0"
PCYawTurnFactor = "20.0"

PitchTurnFactor = "1.0"
YawTurnFactor = "1.0"

VehiclePosition = "common.vehiclepositions.passenger"
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!
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: [Tutorial]making units use their own weapons in vehicles

Post by Fiodis »

Holy Dr. Diet Pepper! :o How did you figure this was possible in the first place? Excellent find!
User avatar
naru1305
Major General
Major General
Posts: 657
Joined: Fri Jan 07, 2011 4:57 pm
Games I'm Playing :: SWBF2
Location: Germany
Contact:

Re: [Tutorial] Making units use their own weapons in vehicle

Post by naru1305 »

wow my friend, this is awesome, thx so much :bowdown:
User avatar
Cerfon Rournes
Master Bounty Hunter
Master Bounty Hunter
Posts: 1558
Joined: Thu Jul 08, 2010 5:53 pm
Projects :: WIP. I will reveal what it is later on..
Games I'm Playing :: SWBF2-SWRC
xbox live or psn: No gamertag set
Location: New York, USA
Contact:

Re: [Tutorial] Making units use their own weapons in vehicle

Post by Cerfon Rournes »

Amazing! :shock:
User avatar
acryptozoo
Master Bounty Hunter
Master Bounty Hunter
Posts: 1642
Joined: Wed Jun 03, 2009 3:14 pm
Projects :: Yavin Mappack
Games I'm Playing :: Homeworld 2
xbox live or psn: acryptozoo
Location: in the jungles of Yavin IV
Contact:

Re: [Tutorial] Making units use their own weapons in vehicle

Post by acryptozoo »

Extremely useful great job :D
User avatar
DarthD.U.C.K.
Master of the Force
Master of the Force
Posts: 6027
Joined: Wed Sep 27, 2006 11:05 am
Location: Duckburg, Germany

Re: [Tutorial] Making units use their own weapons in vehicle

Post by DarthD.U.C.K. »

thanks :D
i found it out while setting up the improved gunship and browsing through the odfparameter-list and the stock gunships odf, its in it but commented out.
User avatar
Delta-1035
Sith Master
Sith Master
Posts: 2651
Joined: Mon Aug 04, 2008 10:32 am
Projects :: TOR GCWII GCW1035 BF1035
xbox live or psn: Johnny_Sciroppo
Location: Pizza Land

Re: [Tutorial] Making units use their own weapons in vehicle

Post by Delta-1035 »

Wow, I will try this out for sure.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: [Tutorial] Making units use their own weapons in vehicle

Post by Marth8880 »

Would it be at all possible to make it so the unit crouches when the crouch key is pressed? The reason for this is that I'm trying to replicate the Mass Effect cover system for pretty obvious reasons. What I plan on doing is placing invisible turrets in cover spots and using your method for making it so units can shoot their normal weapons out of the turret.
User avatar
Cerfon Rournes
Master Bounty Hunter
Master Bounty Hunter
Posts: 1558
Joined: Thu Jul 08, 2010 5:53 pm
Projects :: WIP. I will reveal what it is later on..
Games I'm Playing :: SWBF2-SWRC
xbox live or psn: No gamertag set
Location: New York, USA
Contact:

Re: [Tutorial] Making units use their own weapons in vehicle

Post by Cerfon Rournes »

Marth8880 wrote:Would it be at all possible to make it so the unit crouches when the crouch key is pressed? The reason for this is that I'm trying to replicate the Mass Effect cover system for pretty obvious reasons. What I plan on doing is placing invisible turrets in cover spots and using your method for making it so units can shoot their normal weapons out of the turret.
This was the "cover idea" that I was telling you about. Not sure about crouch, but here is how I was able to achieve a similar effect.
First, made a crate for the cover. Then put two nulls right over each other. (hp1 and hp2)
Hp1 uses the standing animation, and hp2 uses the crouching animation. In this way, you can switch between 'turrets' to make it look like you are standing and crouching, and still fire your weapon and throw nades. I was successful in making this work, to an extent; however, the system has many bugs. For example, after you leave the 'turret', the camera angle stays with the crate. Also, after you switch between positions a few times, the camera goes to the main hardpoint and stays there.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: [Tutorial] Making units use their own weapons in vehicle

Post by Marth8880 »

Hmm. I was thinking of a 9pose where the unit is crouching until it shoots, which it then stands, aims and shoots, and goes back into cover once it's no longer shooting.
User avatar
Cerfon Rournes
Master Bounty Hunter
Master Bounty Hunter
Posts: 1558
Joined: Thu Jul 08, 2010 5:53 pm
Projects :: WIP. I will reveal what it is later on..
Games I'm Playing :: SWBF2-SWRC
xbox live or psn: No gamertag set
Location: New York, USA
Contact:

Re: [Tutorial] Making units use their own weapons in vehicle

Post by Cerfon Rournes »

Interesting; sounds feasible.
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: [Tutorial] Making units use their own weapons in vehicle

Post by Fiodis »

What about the AI not using the system at all? Could be interesting for some scripted SP campaign, but for larger-battle BF2 style gameplay I don't think it would work out so well.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: [Tutorial] Making units use their own weapons in vehicle

Post by Marth8880 »

Oh, no, yeah, of course not in Instant Action. Singleplayer campaign would be its only environment for its use, no doubt about that.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: [Tutorial] Making units use their own weapons in vehicle

Post by [RDH]Zerted »

DarthD.U.C.K. wrote:...browsing through the odfparameter-list and the stock gunships odf, its in it but commented out.
So maybe there was more of a point in having units with rockets in space maps.

Somehow I sense a future of mine throwing vehicles... Did you try it with a hero?
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: [Tutorial] Making units use their own weapons in vehicle

Post by Fiodis »

[RDH]Zerted wrote:Somehow I sense a future of mine throwing vehicles... Did you try it with a hero?
Didn't Dann_Boeing have mine-throwing vehicles in a few of his maps?
User avatar
Dakota
Field Commander
Field Commander
Posts: 991
Joined: Mon Dec 06, 2010 8:21 pm
Projects :: making random weapon assets
Games I'm Playing :: SWBF2 and more
xbox live or psn: PS3 beats xbox
Location: at a computer desk floating around in space

Re: [Tutorial] Making units use their own weapons in vehicle

Post by Dakota »

Fiodis wrote:
[RDH]Zerted wrote:Somehow I sense a future of mine throwing vehicles... Did you try it with a hero?
Didn't Dann_Boeing have mine-throwing vehicles in a few of his maps?

Yes.

off-topic: curses, that reminds me that i forgot to add a mine layer vehicle to my mod... one of these days...
Post Reply