Ok, so I have an enemy AI character, built the character with the 3rd person ultimate character controller kit and he is running around, when I move the UnityEngine.NavMeshAgent - thats cool.
1.)
Also I can turn on Aiming at start if I set the ability to automatic ... but not inside a script
this:
has almost no effect, the weapon seems to move slightly, but it's not aiming forward.
2.)
ok, next thing, setting the aim direction - I thought creating and attaching a look source with the event:
would work, but somehow, this event is passed to the KinematicObjectManager.cs and there it looks for an attached camera component
( m_AttachedCamera = lookSource.GameObject.GetCachedComponent<CameraController>()
- of course my AI doesn't have a camera, so I'm stuck here.
3.)
Third point: Shooting
The documentation was no help regarding this point, so there are items, itemAbilities, equippedItems and you can Use() them or Fire() ShootableWeapons - all this may can be done with the eventSystem too - but I have no idea how. Digging through the code, the forum and everything, I think there must be a super simple answer but I can't find it.
Why can't I just use the BehaviourTree solution - well Humans are not the only enemies in my game, I also have turrets, mines, drones and the human ones can be quite stupid, no complex behaviour needed.
And the way the code is structured, there must be a good solution.
Thanks in advance
Whole class here:
1.)
Also I can turn on Aiming at start if I set the ability to automatic ... but not inside a script
this:
C#:
EventHandler.ExecuteEvent<bool>(_character.gameObject, "OnAimAbilityAim", true);
has almost no effect, the weapon seems to move slightly, but it's not aiming forward.
2.)
ok, next thing, setting the aim direction - I thought creating and attaching a look source with the event:
C#:
lookAtPlayer = new LookAtPlayer();
EventHandler.ExecuteEvent<ILookSource>(_character.gameObject, "OnCharacterAttachLookSource", lookAtPlayer);
public class LookAtPlayer : ILookSource
{
[...] interface implementation [...]
}
would work, but somehow, this event is passed to the KinematicObjectManager.cs and there it looks for an attached camera component
( m_AttachedCamera = lookSource.GameObject.GetCachedComponent<CameraController>()
- of course my AI doesn't have a camera, so I'm stuck here.
3.)
Third point: Shooting
The documentation was no help regarding this point, so there are items, itemAbilities, equippedItems and you can Use() them or Fire() ShootableWeapons - all this may can be done with the eventSystem too - but I have no idea how. Digging through the code, the forum and everything, I think there must be a super simple answer but I can't find it.
Why can't I just use the BehaviourTree solution - well Humans are not the only enemies in my game, I also have turrets, mines, drones and the human ones can be quite stupid, no complex behaviour needed.
And the way the code is structured, there must be a good solution.
Thanks in advance
Whole class here:
C#:
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Events;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyAttack : MonoBehaviour
{
public float attackRangeMin;
public float attackRangeMax;
UltimateCharacterLocomotion _character;
public Transform target;
public LookAtPlayer lookAtPlayer;
bool _lastIsAiming = false;
public bool isAiming = false;
IEnumerator Start()
{
yield return null;
_character = GetComponentInParent<UltimateCharacterLocomotion>();
if (!_character) throw new System.Exception("Character is NULL");
if (!_character.gameObject) throw new System.Exception("Character GO is NULL");
lookAtPlayer = new LookAtPlayer();
// Throws exception so outcommented to test the aiming
//EventHandler.ExecuteEvent<ILookSource>(_character.gameObject, "OnCharacterAttachLookSource", lookAtPlayer);
lookAtPlayer.Transform = target;
_lastIsAiming = isAiming;
}
private void Update()
{
if (_lastIsAiming != isAiming)
{
Debug.Log("Aim: " + isAiming);
EventHandler.ExecuteEvent<bool>(_character.gameObject, "OnAimAbilityAim", isAiming);
_lastIsAiming = isAiming;
}
if (Input.GetKeyDown(KeyCode.O))
{
// fire
}
}
public class LookAtPlayer : ILookSource
{
public GameObject GameObject { get; set; }
public Transform Transform { get; set; }
public float LookDirectionDistance { get; set; }
public float Pitch => 0;
public Vector3 lookDirection;
public Vector3 lookPosition;
public Vector3 LookDirection(bool characterLookDirection)
{
return lookDirection;
}
public Vector3 LookDirection(Vector3 lookPosition, bool characterLookDirection, int layerMask, bool useRecoil)
{
return lookDirection;
}
public Vector3 LookPosition()
{
return lookPosition;
}
}
}
Last edited: