|
Post by Invector on Nov 1, 2018 16:10:21 GMT
I know this was mentioned for future updates, but has anyone figured out how to have the A.I. Follow you as you move compared to the waypoint system? Thanks! Hey man. To make an AI like a companion you can create a new AI code that inherits the AI type that you want (melee or shooter). Something like that using Invector.vEventSystems;
using System.Collections.Generic;
using UnityEngine;
namespace Invector.vCharacterController.AI
{
[vClassHeader(" AI COMPANION", iconName = "AI-icon")]
public class vAICompanion:vControlAIMelee
{
public Transform player;
}
} And you need to create a new action to AI follow the player. namespace Invector.vCharacterController.AI.FSMBehaviour
{
public class vFollowPlayerAction :vStateAction
{
public override string defaultName
{
get
{
return "Follow Player";
}
}
public float maxDistanceToStartFollow;
public float minDistanteOfTheTarget;
public override void DoAction(vIFSMBehaviourController fsmBehaviour, vFSMComponentExecutionType executionType = vFSMComponentExecutionType.OnStateUpdate)
{
if(fsmBehaviour is vAICompanion)
{
FollowTarget(fsmBehaviour as vAICompanion);
}
}
public virtual void FollowTarget(vAICompanion companion)
{
if (!companion || !companion.player) return;
var dist = Vector3.Distance(companion.transform.position, companion.player.position);
if (dist > maxDistanceToStartFollow) companion.MoveTo(companion.player.position);
else if(dist<=minDistanteOfTheTarget) companion.Stop();
}
} }
|
|
|
Post by alueckard on Dec 8, 2018 7:27:19 GMT
Hello, can anybody make an example of how do that if is much to ask. thanks!
|
|
|
Post by tchrisbaker on Dec 9, 2018 0:40:41 GMT
I tried to do this but when I made a script like vAICompanion, and put it on my companion, my FSM wouldn't run. I know this is messy and a bit of a hack but it did work using System.Collections.Generic; using UnityEngine;
namespace tchrisbaker { public class AICompanion : MonoBehaviour { [HideInInspector]
public Transform player;
void Start() { GameObject playerGO = GameObject.FindGameObjectWithTag("Player"); //Debug.Log(playerGO); if (playerGO != null) { player = playerGO.transform; } else { Debug.LogError("AICompanion could not find player"); } } } }
using UnityEngine;
namespace Invector.vCharacterController.AI.FSMBehaviour { public class FollowPlayerAction :vStateAction { public override string defaultName { get { return "Follow Player"; } }
public float maxDistanceToStartFollow; public float minDistanteOfTheTarget;
public override void DoAction(vIFSMBehaviourController fsmBehaviour, vFSMComponentExecutionType executionType = vFSMComponentExecutionType.OnStateUpdate) { tchrisbaker.AICompanion companionScript = fsmBehaviour.gameObject.GetComponent<tchrisbaker.AICompanion>(); FollowTarget(companionScript, fsmBehaviour); }
public virtual void FollowTarget(tchrisbaker.AICompanion companion, vIFSMBehaviourController fsmBehaviour) { if (!companion || !companion.player) return; var dist = Vector3.Distance(fsmBehaviour.transform.position, companion.player.position); if (dist > maxDistanceToStartFollow) fsmBehaviour.aiController.MoveTo(companion.player.position); else if(dist<=minDistanteOfTheTarget) fsmBehaviour.aiController.Stop(); } } }
I know it's inefficient to do this every frame but it got me started at least tchrisbaker.AICompanion companionScript = fsmBehaviour.gameObject.GetComponent<tchrisbaker.AICompanion>();
|
|
nexal
Full vMember
Posts: 57
|
Post by nexal on Jan 21, 2019 15:54:02 GMT
Hi, with regard to Invector "AI companion" I would like to know if there is the possibility to create an AI companion that simply follow the player, without a waypoint and walking at the same speed of the player and can walk behind or right or left to the player with script adjustments. I tried with the dedicated scripts invector but does not work and I do not think they are made for this but for combat.Thank you Update: I found a way to make the companion follow the player even simply walking, eliminating the run section in the animator melee combat but I realized that the companion does not climb the stairs even if I adjust on the capsule collider. Some idea?
|
|
nexal
Full vMember
Posts: 57
|
Post by nexal on Jan 26, 2019 10:34:26 GMT
Does anyone know if the companions or enemy can climb steps of various heights ? Unfortunately, in my game there are many.
|
|
|
Post by tchrisbaker on Jan 30, 2019 5:44:54 GMT
Does anyone know if the companions or enemy can climb steps of various heights ? Unfortunately, in my game there are many. I think that has to do with the settings in the Navmesh Agent
|
|
nexal
Full vMember
Posts: 57
|
Post by nexal on Jan 30, 2019 14:16:00 GMT
tchrisbaker thanks for the reply. I tried everything with the navmesh agent but nothing. In particular, on what values do we need to act and you have an example about it?
|
|
nexal
Full vMember
Posts: 57
|
Post by nexal on Jan 31, 2019 8:40:14 GMT
tchrisbaker thanks for the reply. I tried everything with the navmesh agent but nothing. In particular, on what values do we need to act and you have an example about it? I solved, the problem was in bake and in agent in the step height, I changed the values and now it's ok. I did not think it was necessary for this.
|
|
|
Post by tezza73 on Mar 25, 2019 20:50:13 GMT
How did you make the companion follow the player?
|
|