BD & FPC questions

Nemesis7

New member
Hello all,

I have several interrogations about BD and FPC, so if any can help on that...

1. When my AI character shoots, I would like they make pauses after some shots, which they don't, they see my character and they don't stop shooting, I'd like them to stop and move to cover or something like that after some gunshot, what would be my best solution for that ?

2. When the AI character shoot at my player, some time there are objects between them, but the AI keeps shooting, it doesn't see the object, like a furniture and even sometimes a wall, they are capable to see though the objects, how can I solve that ?

3. I am having a big problem still with my AI, once they have seen the target, they shoot, when the target is out of their range, they chase, every time they have to chase, they get stuck because they went somewhere they couldn't walk... as if they were not respecting the navmesh anymore, that's really hard to understand...

4. I am considering to buy the hit box asset, but I would like to figure how can I access to the capsule collider in the script and I don't find it, so if you can help on that, or maybe you already have an integration for that...


I am also considering buying A* pathfinding pro, do you think it would be worth it to add that to the AI character ?
 
1. When my AI character shoots, I would like they make pauses after some shots, which they don't, they see my character and they don't stop shooting, I'd like them to stop and move to cover or something like that after some gunshot, what would be my best solution for that ?
You could add a Wait task immediately after the Start Stop Use task. You can then increase the Use Rate on the weapon so it can only fire a limited amount of time.

2. When the AI character shoot at my player, some time there are objects between them, but the AI keeps shooting, it doesn't see the object, like a furniture and even sometimes a wall, they are capable to see though the objects, how can I solve that ?
I'm assuming that you are using the Can See Object task? Make sure it is being reevaluated. You may also want to adjust the offsets to relocate where the raycast starts/ends when determining if any objects are between the start and end points.

3. I am having a big problem still with my AI, once they have seen the target, they shoot, when the target is out of their range, they chase, every time they have to chase, they get stuck because they went somewhere they couldn't walk... as if they were not respecting the navmesh anymore, that's really hard to understand...
Are you able to reproduce it within the integration demo scene?

4. I am considering to buy the hit box asset, but I would like to figure how can I access to the capsule collider in the script and I don't find it, so if you can help on that, or maybe you already have an integration for that...
The character controller isn't integrated with any hitbox assets, but you can get the capsule collider by doing a GetComponentInChildren and searching for the CapsuleColliderPositioner. The capsule collider will be attached to that same GameObject.

I am also considering buying A* pathfinding pro, do you think it would be worth it to add that to the AI character ?
I would look at the feature list for A* and determine if it's something that you can use. It is integrated with both the character controller and Behavior Designer so that part is no problem.
 
Hi, A week later, I tried what you told me, I found some stuff by mylself too so :

1. Pause after some shoots : I can't figure how to do it, I try to work from your demo tree. I tried what you said but what I wait it's : he shoot 3/5 times (automatic gun), then he moves, but once he sees the character, he actually doesn't stop the attack status at all, how can I pause the attack task to make it wait a bit ?
OpsiveWait.JPG

2. I use the target bones as in your demo, I changed that, so far it seems to work.

3. I think I found, and yes I have been able to reproduce, if the radius of the baked agent is 0.5, it gets stuck, if I increase this radius, it does not, but that is a little problem because with a bigger radius, my AI can't pass though doors anymore on the navmesh... So I don't really know what to do (except having pathfinding pro which seems to solve this kind of problem).

4. Solved

I would add a 5th question :

I am having problem with the near distance attack, in the demo and in any custom tree with my agent.
In the demo scene, if I attack the agent but he can't see me, he runs at me, and keep running at me :

Opsive2.JPG

It does the same with my trees/agent.

I also have this problem if my agent is in root motion locomotion, it does not respect the near distance at all and "crash" once he sees the player, in the demo scene, it's possible to get back in normal by running far from the agent, in my custom agent situation, it's impossible.

What option do I have to solve that ?

Also, when I was making research to solve those things, I found the Deathmatch AI kit, it seems to be the solution to everything, is there any ETA for it or any way to have the older version ? to see the trees and to understand :)

Thank you for your time.
 
1. Pause after some shoots : I can't figure how to do it, I try to work from your demo tree. I tried what you said but what I wait it's : he shoot 3/5 times (automatic gun), then he moves, but once he sees the character, he actually doesn't stop the attack status at all, how can I pause the attack task to make it wait a bit ?
Immediately after the StartStopUse task starts which starts the attack you could then have another StartStopUse task which stops the attack.

3. I think I found, and yes I have been able to reproduce, if the radius of the baked agent is 0.5, it gets stuck, if I increase this radius, it does not, but that is a little problem because with a bigger radius, my AI can't pass though doors anymore on the navmesh... So I don't really know what to do (except having pathfinding pro which seems to solve this kind of problem).
The A* Pathfinding Project does seem like it may work for this situation. It sounds like the NavMeshAgent is trying to move into areas that it shouldn't.

What option do I have to solve that ?
Is a seek task running when the character is moving into you? I've been updating the demo scene for version 2.2 and haven't noticed this occurring but will check again.

Also, when I was making research to solve those things, I found the Deathmatch AI kit, it seems to be the solution to everything, is there any ETA for it or any way to have the older version ? to see the trees and to understand
Unfortunately no ETA yet and the old version won't work with the current version of the character controller.
 
Quick reply :

The Start/stop task :

OpsiveWait2.JPG

It does not stop attacking... Should I try a parallel one branch start the other stops ?

I've been updating the demo scene for version 2.2 and haven't noticed this occurring but will check again.

I am not under 2.2, I don't see that on the store ? the lastest is 2.1.10 and I am using FCC 2.1.9, I did not update BD either, should I? Is it risky ?
 
It does not stop attacking... Should I try a parallel one branch start the other stops ?
Do you have AlwaysReturnSuccess enabled? This will make sure it always returns during that tick. But if the task isn't stopping then the use ability is still running. In this case you could try switching your shootable weapon to a semi auto fire mode so it just fires one shot at a time. Then you'll completely control the firing within the behavior tree.

I am not under 2.2, I don't see that on the store ? the lastest is 2.1.10 and I am using FCC 2.1.9, I did not update BD either, should I? Is it risky ?
2.2 isn't released yet, hopefully very soon. When that is released I'll have an updated integration scene. Especially with these recent changes I do recommend updating when it is released.
 
So,
I did not make the update, I will check that later.

I solved the waiting after shooting, and it seems I solved the near distance issue in most of the situation, I played with some settings and some task and it very rarely gets crazy (so far).

I bought A* pathfinding, and I have a little red line :

Opsive3.JPG

Opsive4.JPG

I tried to delete the override, just to see, it works (but still need the navmesh ability ?) and before to go anywhere it rotates like crazy.

I followed the instruction of the integration I think, what did I miss?
 
The A* Pathfinding integration has been updated for the most recent version so you'll want to first update to 2.2. From what I remember that override was the only thing that changed for 2.2 but just to be sure I would update to 2.2.
 
Hi,
So I made the update, and I am having some trouble, but one mostly.

I have a script which activates on AI death, it instantiates a prefab of ammunition, The ammo created changes its value on spawned.
It used to be written like that :

Code:
(test.name == "myAmmo") MyItem.ItemTypeCounts[0].Count = Random.Range(11, 46);

where test is the prefab, myItem is the item pickup component.

Now it does not work anymore as said in your update documentation, so I tried to understand the new code but at the end the only way I found to make it work as before is :

Code:
if (test.name == "myAmmo") MyItem.m_ItemDefinitionAmounts[0].Amount = Random.Range(11, 46);

I also changed the m_ItemDefinitionAmounts as a public variable.

Unfortunately, if it works very well in the editor, it does not in build, on the debug I hae plenty of errors when it tried to instantiate.

So, simple question, what did I do wrong ? What should I do?

Also, what is the best way in the animator to put 2 animations which do the same thing, but randomize them to not always have the same which plays ?

Thanks for your answers.
 
Unfortunately, if it works very well in the editor, it does not in build, on the debug I hae plenty of errors when it tried to instantiate.
What are those errors? ItemDefinitionAmounts may be null or have a length of zero so you'll want to first check for null/0 before assigning an element to it.

Also, what is the best way in the animator to put 2 animations which do the same thing, but randomize them to not always have the same which plays ?
This will take a new ability, similar to the Idle ability.
 
The line which poses problem is actually none of those I showed, I should have looked more carefully at the error.

Here are the console error, on build only, it perfectly works in the editor :

Code:
NullReferenceException: Object reference not set to an instance of an object
  at ObjetOnDead.ObjetsToSpawnSpawner () [0x00029] in D:\MyProject\Assets\AI\ObjetOnDead.cs:23 
  at UnityEngine.Events.InvokableCall.Invoke () [0x00017] in C:\buildslave\unity\build\Runtime\Export\UnityEvent\UnityEvent.cs:166 
  at UnityEngine.Events.UnityEvent`3[T0,T1,T2].Invoke (T0 arg0, T1 arg1, T2 arg2) [0x00046] in C:\buildslave\unity\build\Runtime\Export\UnityEvent\UnityEvent\UnityEvent_3.cs:63 
  at Opsive.UltimateCharacterController.Traits.Health.Die (UnityEngine.Vector3 position, UnityEngine.Vector3 force, UnityEngine.GameObject attacker) [0x001e9] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Traits\Health.cs:457 
  at Opsive.UltimateCharacterController.Traits.CharacterHealth.Die (UnityEngine.Vector3 position, UnityEngine.Vector3 force, UnityEngine.GameObject attacker) [0x00001] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Traits\CharacterHealth.cs:109 
  at Opsive.UltimateCharacterController.Traits.Health.OnDamage (System.Single amount, UnityEngine.Vector3 position, UnityEngine.Vector3 direction, System.Single forceMagnitude, System.Int32 frames, System.Single radius, UnityEngine.GameObject attacker, System.Object attackerObject, UnityEngine.Collider hitCollider) [0x00322] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Traits\Health.cs:372 
  at Opsive.UltimateCharacterController.Traits.CharacterHealth.OnDamage (System.Single amount, UnityEngine.Vector3 position, UnityEngine.Vector3 direction, System.Single forceMagnitude, System.Int32 frames, System.Single radius, UnityEngine.GameObject attacker, System.Object attackerObject, UnityEngine.Collider hitCollider) [0x00001] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Traits\CharacterHealth.cs:94 
  at Opsive.UltimateCharacterController.Traits.Health.Damage (System.Single amount, UnityEngine.Vector3 position, UnityEngine.Vector3 direction, System.Single forceMagnitude, System.Int32 frames, System.Single radius, UnityEngine.GameObject attacker, System.Object attackerObject, UnityEngine.Collider hitCollider) [0x00037] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Traits\Health.cs:273 
  at Opsive.UltimateCharacterController.Items.Actions.ShootableWeapon.HitscanFire (System.Single strength) [0x00200] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Items\Actions\ShootableWeapon.cs:949 
  at Opsive.UltimateCharacterController.Items.Actions.ShootableWeapon.Fire (System.Single strength) [0x000cf] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Items\Actions\ShootableWeapon.cs:737 
  at Opsive.UltimateCharacterController.Items.Actions.ShootableWeapon.UseItem () [0x00092] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Items\Actions\ShootableWeapon.cs:655 
  at Opsive.UltimateCharacterController.Character.Abilities.Items.Use.LateUpdate () [0x0008f] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Character\Abilities\Items\Use.cs:632 
  at Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.LateUpdateActiveAbilities (Opsive.UltimateCharacterController.Character.Abilities.Ability[] abilities, System.Int32& abilityCount) [0x0000f] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Character\UltimateCharacterLocomotion.cs:1029 
  at Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.LateUpdateUltimateLocomotion () [0x00023] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Character\UltimateCharacterLocomotion.cs:1015 
  at Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.UpdatePositionAndRotation () [0x00014] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Character\UltimateCharacterLocomotion.cs:826 
  at Opsive.UltimateCharacterController.Character.CharacterLocomotion.UpdatePositionAndRotation (System.Boolean fromAnimatorMove) [0x00033] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Character\CharacterLocomotion.cs:517 
  at Opsive.UltimateCharacterController.Character.CharacterLocomotion.OnAnimatorMove () [0x000dc] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Character\CharacterLocomotion.cs:1471 
  at Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.OnAnimatorMove () [0x00103] in D:\MyProject\Assets\Opsive\UltimateCharacterController\Scripts\Character\UltimateCharacterLocomotion.cs:1757 
 
(Filename: D:/MyProject/Assets/AI/ObjetOnDead.cs Line: 23)


Which means the problem comes from this line :

Code:
r.GetItemIdentifierAmount(ItemDispos[i]) == 1

Where r is "Inventory" component. I changed the name with 2.2 for GetItemIdentifier (I already forgot what it was).

Any idea what I did wrong ?
 
Based off of that error the only thing that it could be is that the r variable or ItemDispos variable is null.
 
The ItemDispos is not null, and the r variable is from var r = gameObject.GetComponent<Inventory>();

And it works very well in editor, I get the errors only on build, which makes it weirder...
 
I would place a lot of outputs in your code to determine what is null while making a build.
 
I finally found... stupid mistake from me (obviously)

I have another question, when I equip a weapon, the muzzleflash plays, I have no idea why because I am not shooting, it's muzzle flash from the store, not from the demo, I checked on legacy forum it seemed it happened already, aren't there any solution other than create custom prefab spawnin on shot ?

It's several particle system, I don't really understand it plays once on equip... if you have seen that before, I am probably missing something...
 
Last edited:
Glad you got it! For these separate issues can you please post a new thread so it makes it easier to search?

Just based on the description though are you using a particle system for the muzzle flash? Maybe that particle system is set to play on awake? Right now the controller doesn't support a particle system for the muzzle flash and it has to be a texture that fades.
 
Well, the "funny" part is that the problem occurs only on automatic weapon, nothing to signal on semi auto.

It's indeed a particle muzzle flash, I'd rather find the solution than to change (coz I ilke those flash), my mind has problem to understand how something can be wront with automatic gun but not semi-auto.
 
I am surprised that it works at all. Right now particle muzzle flashes are not support though I do have it on my list.
 
Top