PlayerInput (camera) with Ai Agent (movement)

Absent83

Member
Hallo!

Please help to combine character controls PlayerInput (camera) with Ai Agent (movement):

1.

I need to make FirstPersonView character to follow some path or to move with AI Agent (i.e. NavMeshAgent) and simultaneously rotate the character camera by UnityInput (i.e. mouse).
I can do this by moving character on MovingPlatform, but in this case I have no any animations (bob/spring…).

2.
And in the second variant I need the same, but when character is moving camera is looking forward, and when character stops, player can control rotation by UnityInput.
 
For both of these I would create a new ability that controls the character's input. When this ability is active you can set the m_CharacterLocomotion.InputVector to Vector2.zero and then control the movement from there. With this setup you will have full control over the camera.
 
I have an error on building character in this case:

1539384565462.png



1539384776492.png

NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Editor.Managers.CharacterManager.DrawNewCharacter () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/CharacterManager.cs:341)
Opsive.UltimateCharacterController.Editor.Managers.CharacterManager.OnGUI () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/CharacterManager.cs:173)
Opsive.UltimateCharacterController.Editor.Managers.MainManagerWindow.OnManagerGUI () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/MainManagerWindow.cs:407)
Opsive.UltimateCharacterController.Editor.Managers.MainManagerWindow.OnGUI () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/MainManagerWindow.cs:310)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:295)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:288)
UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:255)


Unity 2017.3.1p1 (64-bit)
UCC 2.0.3
 
Thanks - change line 341 of CharacterManager from:

Code:
var navMeshAgent = character.GetComponent<UnityEngine.AI.NavMeshAgent>();

to:

Code:
var navMeshAgent = m_AddCharacter.GetComponent<UnityEngine.AI.NavMeshAgent>();
 
just in case I inform you that, that there are else two similar lines in CharacterManager: 744 and 750.

And the line 874 has the similar "GetComponent<UnityEngine.AI.NavMeshAgent>()".

Maybe they are also woud be changed...
 
Last edited:
Can you describe more detailed, how to control FirstPersonView character by AI Agent (i.e. NavMeshAgent) and simultaneously independently control (rotate) the character`s camera by UnityInput (i.e. mouse). Camera view direction souldn`t change character moving direction, controlling by AI.
And when character is walking/running (moving) by AI, FirstPersonView weapon would be animated (bob/spring…).


Thank you!
 
Top