News › Forums › Squad Command: Adv Warfighter AI › General Discussion and Troubleshooting › Gun Controller Script
This topic contains 8 replies, has 2 voices, and was last updated by bucketloader 4 months ago.
-
AuthorPosts
-
March 3, 2022 at 6:57 pm #36440
HI
I am making a new gun for a mech , but the gun controller script uses a legacy ellipsoid particle emitter (TRACER FIRE) . All I seem to have is particle systems. I cannot locate the emitter in the project that the original m4mb prefab gun controller script uses.Is there some way around this ?
March 3, 2022 at 11:25 pm #36442After quite sometime I sort have found the emitter. Its not in the assets anyplace, only defined in the gun controller script itself. If you use the little gear icon to try to find the asset it doesn’t find anything , but if you actually click the name it shows up.
I tried to modify a new script to use the particle system but found it wasn’t easy to get at the velocity. And iam not very good at C#
I will play with it some more and see if I can get the mech gun to work right.
Would there be any problems adding a bunch of guns to the mech? , I assume I just need to add some more script and mount points to add more guns.
-
This reply was modified 4 months, 1 week ago by
bucketloader.
March 4, 2022 at 10:28 am #36456Hey there @bucketloader. When you are talking about adding more guns to the mech, will they be aimed and fired independently, or are they mounted together and fire together?
March 4, 2022 at 1:19 pm #36473The mech has 2 gun pods (left and right ) each has 2 cannons . it also has two more gun spots around its body and two rocket packs on top. (just trying to get the gun pods working first, so 4 guns
) All of the weapons are fixed in place and have to be aimed by turning the body , which seems to be working.
I have managed to get 3 guns on it so far (used a beefed up m4 prefab for now that doesn’t render ) and added 2 more weaponfire1,2 and aim and fire1,2 scripts. and weapon fire1,2 behaviors
It seems to be sort of working but looks like its still only firing one gun . Think I need to fiddle with the aim and fire part more in the mech behavior, its a copy of the attackerbehavior ,
Ah looks like its using the default attack , ill have to change that now by the looks of it .(its standing out in the open and the defenders walk up to it )
For now I want it to aim at one target and fire the canons all 4 at the same time . I assume I can just use the one aim and not have to put one on each gun.
-
This reply was modified 4 months ago by
bucketloader.
-
This reply was modified 4 months ago by
bucketloader.
-
This reply was modified 4 months ago by
bucketloader.
March 4, 2022 at 5:50 pm #36477Right - That’s why I as asking about how the misc. guns were aimed. Since they are all aimed and fired together, it should be relatively easy to convert the AimAndFireElement to use an array of guns, gun controllers, gun mounts, etc. and loop through the array on each relevant method.
This gets a little trickier if each gun fires separately, reloads separately, etc. You would either have to include multiple aim and fire elements and loop through those when aiming/firing, etc. or create a more complicated aim and fire element. In addition, you might have to change the AI behaviors a bit to account for not stopping and waiting during reload, etc. It’s all do-able though.
March 4, 2022 at 6:23 pm #36479I am trying the multiple elements approach. I duplicated the aim and fire,weapon fire scripts and just added a number to the classes so I end up with weaponfire1 , weaponfire2 etc. Also made weaponfire1,2 behaviors, in the Ai on the last one (pencil icon) I now have well 3 aimanandfire,1,2 with the different mounts and stuff.
It mounts the guns fine , and one of them for sure works. I am going to just fire one gun at a time tomorrow so I can make sure they at least work individually , then ill try to get them all to work again.
I might gut the scripts a bit I don’t need reloading , im pretending it has unlimited ammoHehe he wastes the defenders in about 10-20 secs now , ill tone him down when I get things working.
That array idea sounds cool but I think I would end up making it way worse. Im really dangerous with C lol , and I got rain mad at me once when i had duplicate classes , but I fixed that
I thought he was using the default attack but after looking at it while its running and sticking a couple of breakpoints in , I see he is just using his behavior, so once I confirm the guns work individually ill try to see whats messing up the multiple gun firing.
March 4, 2022 at 8:25 pm #36480Im starting to run out of ideas.
Tried firing a second different gun, it looks like it is shooting the proper one from the behavior while it is running, but it always animates the very first weapon . ( I removed all of the guns but weapon1 In the behavior) Part I don’t know right now is it actually shooting from the one I want and animating the first one. From what I remember in the script for the hit it will just tell me the mech object hit them
I made another gun and changed the controller script to another different copy (changed the class etc to guncontroller1)and it does the same thing. So I have two separate guns now too. I tried moving the order of gun mounts around , and element order didn’t affect it.
But the particles and gun emitters etc are still the same names.Can I make the raycast visible easily ? Or a second thought can I change the scripts so they are not global , The fireweapon custom action shows as being global maybe if I can make them each private or something .
March 4, 2022 at 11:21 pm #36482Help me to understand a bit pls. Sorry it got a bit long
if I have two different aimandfire control scripts[RAINSerializableClass, RAINElement(“Aim and Fire Control”)]
public class AimAndFireElement : CustomAIElement[RAINSerializableClass, RAINElement(“Aim and Fire Control1″)]
public class AimAndFireElement1 : CustomAIElementI assume these would create two separate classes or serialzed elements that don’t share memory.
/// <summary>
/// The gun controller that provides direct fire/reload methods.
/// </summary>
private GunController _gunController = null;/// <summary>
/// Accessor to the Gun Controller - read only.
/// </summary>
public GunController Controller
{
get { return _gunController; }
}/// <summary>
/// Called when the AI is initialized and the body has been ste.
/// Set up gun parenting and grab the AI Animator and the Gun Controller
/// </summary>
public override void BodyInit()
{
base.BodyInit();if (_gunPrefab == null || _gunMount == null)
throw new System.Exception(“AimAndFireELement requires a Gun Prefab and Gun Mount”);GameObject tGun = (GameObject)GameObject.Instantiate(_gunPrefab);
tGun.transform.parent = _gunMount;
tGun.transform.localPosition = Vector3.zero;
tGun.transform.localRotation = Quaternion.identity;_animator = AI.Animator as MecanimAnimator;
if (_animator == null)
throw new System.Exception(“AimAndFireELement only works with a MecanimAnimator on your AI”);_gunController = tGun.GetComponentInChildren<GunController>();
if (_gunController == null)
throw new System.Exception(“AimAndFireELement requires a GunController located on the Gun Prefab”);_gunController.shooter = AI.Body;
}Now the big question.. assume I have 3 guns all set up , in rain they are all separate elements,scripts classes etc.
there is two types of guns , one has the regular guncontroller script and the second has a guncontroller1 script , which I also changed the aimand fire1 script to look for that script.
I don’t know in what order it initializes things. Back to the mech it has 3 guns right now setup,
types gun0, gun1,gun0
gun0 = guncontroller script
gun1 = guncontroller1 scriptNow I know it mounts the proper guns in the right place ok, but those are specifically set in the element.
But is there a possibility of it overwriting variables back to gun0 type, because when I tell it to fire the gun1 type and I removed any other fire calls it still fires or appears to be firing from the first gun0 (plain weaponfire scripts etc )
so im thinking its getting the wrong guncontroller somehow. It looks to be working in the behavior tree alright and everything is setup to use element aimandfire1 and weaponfire1 , and it mounts gun1 in the proper mount.Or else some variable is getting overidden when it loads in #3gun gun0
public GunController Controller
{
get { return _gunController; }
}Can I set this to show up in the element somehow. Then I can see if it is getting the right controller.
March 5, 2022 at 10:23 am #36486OK I finally got it all working , lol its awesome he blats the defender team in about 3 seconds.
The problem turned out to be in the weaponfire script , I forgot to change/missed the aimandfire element it was getting.
So I ended up with just using one gun prefab (just a bigger version of the M4 derendered) , I made 3 copies of the aimandfire script,each using a different class and element name. 3 copies of the weaponfire ,with new class names. 4 different elements in the AI. In the mechbehaivoir I just fired all of the guns with a 4 action calls to fireweapon0,1,2,3 under a parallel with a timer. took out the bindings to fireweapon behavior.
It really looks cool when he shoots now all 4 guns shoot at once
The one thing that would be nice if the guncontroller didn’t use that legacy ellipsoid particle. I haven’t been able to reproduce it correctly yet. There is a few bits hiding in it someplace. smoke for one.
-
This reply was modified 4 months, 1 week ago by
-
AuthorPosts
You must be logged in to reply to this topic.