- Home /
Setting up a Character Question.
Hello Guys.
So I'm making a Multiplayer First Person Shooter.
Currently I have weaponmodels with hands attached to them. My Player is a Sphere for test purposes. I also have a model of a soldier which I didn't used until now.
Because my Game will be Multiplayer I want to set up a player with the weapon in his hands. This way I don't need several models for the local player and the other players.
I could make it so that I import the weaponmodel to the soldier model and then model the soldier around it and also animate them both in one model. This way I had to switch the entire soldiermodel when I just switch weapon. This seems to be a lot of work and will probably cause a lot of problems.
So I want to ask wether there is a better way to set up a character or wether you can improve my thoughts.
I hope the question was easy to understand and I also hope that someone knows an answer.
Every help is much appreciated.
I had an idea lately:
There is only one soldier model. The weapon gets spawned in at the right position by maybe the help of an empty gameobject. The weaponmodels and the soldier-model get animated at the same time and in one file but then before importing them into unity get seperated.This way I would have the soldiermodel have animations which fit to the animations the weaponmodels have. The only challenge then would be spawning the weapons in the right position. Every time you change the weapon another weaponmodel gets activated and another fitting idle animations gets played in a loop.
Is this an easy way of doint things or will I run into problems real quick.
I'm open for your ideas this is just what came to my today.
Answer by aldonaletto · Jun 05, 2012 at 12:40 PM
The easiest way is to have an empty game object (say, Weapon) childed to the hand bone. All possible weapons are childed to Weapon, each one previously adjusted to the correct position/rotation. Locate the object Weapon at Start and save a reference to it (or drag it to the reference variable at the Inspector). To select a weapon, deactivate all of the Weapon children and activate only the selected one with GameObject.SetActiveRecursively(onOff).
This works fine for compatible weapons, like rifle, machine gun, rocket launcher etc. but may seem weird when switching to a pistol or - even worse - to an axe or sword. In such cases, maybe the whole character should be switched - or at least its mesh (have not tested this).
Did you look at my comment under the question. The way you are explaining can probably fit really good to it. When I do it as you said and have like different idle animation for a rifle and a pistol. This way I don't have to change the model each time I switch weapon. I just have to switch the idle animation. Do you think this would work?
That's a good idea: have different animations for specific cases - much better than switch the whole mesh. $$anonymous$$aybe you need other animations too - walk, run, fire - but it's much easier to change the animation names in variables, like this:
var weapons: Transform; var anIdle: String; var anWalk: String; var anRun: String; var anFire: String;
function SwitchWeapon(weaponName: String){ // activate the selected weapon, deactivate the others: for (var weapon: Transform in weapons){ weapon.gameObject.SetActiveRecursively(weapon.name == weaponName); } // switch animation set according to weapon: switch (weaponName){ case "Pistol": anIdle = "IdlePistol"; anWalk = "WalkPistol"; anRun = "RunPistol"; anFire = "FirePistol"; break; case "Rifle": case "$$anonymous$$achineGun": case "RocketLauncher": anIdle = "IdleRifle"; anWalk = "WalkRifle"; anRun = "RunRifle"; anFire = "FireRifle"; break; } }
// then use the variables ins$$anonymous$$d of the animation names: ... if (speed < 0.2){ animation.CrossFade(anIdle); } else if (speed < 3.5){ animation.CrossFade(anWalk); } else { animation.CrossFade(anRun); } ...
Yes i thought about it and I think I'm gonna do it so that I will animate the soldier and the weapon in one file and then when I'm ready seperate them into different files. This way the soldier has every animation for every possible weapon.
Btw. I have my script to switch weapon and such already done and it works(I use a two weapons system). So implementing the animation stuff won't be that much of a big deal I hope :).
Thaks aldonaletto you were a great help and managed to form out my first idea so far that I'm really confident about using it.
Huge thanks.
NOTE: you still can have only one weapon object childed to the appropriate bone.
I don't know until now wether I will child it to the bone or maybe have it seperate to the soldier model. I know that when its childed to that bone it will be better for movement but I think it will be more difficult to access it from other script. I will see when I really make it.
PS: With two weapon system I mean you have one weapon on 1 and one on 2 and can replace them by picking another one up.