Entertainment, Game Development.

Behavior Designer – RPR

NOTE: I have discontinued the use of BD for RPR release and will go back to BD once I have more time to play with it.

 

After a very thorough discussion and extensive support from Justin at Behavior Designer, I figured to use BD for my AI in the future projects will be the best.

 

For my first game release I do not have the time to  completely learn and work with therefore I will be sticking with Emerald AI for the moment

 

Below I will touch upon the logic used for the AI *high level* with some screenshots to help. Hopefully it can be of some use to you, because surely it will be to me in the near future for my next release.

 

Follow this link and the links within to get a better understanding what it’s all about: Behavior Tree Overview

Links within: How they work, 3PS, Gladiabots, Other, Video

 

I started off with a basic to-do list:

1. Patrol / wander / SWS
2. Seek / search / within distance / can see object /
3. Follow / move towards / rotate towards / pursue .
4. Decide:
a. Close enough to attack?
b. Close enough for melee attack? / play random melee attack animation
c. if not Range attack; / play random range attack animation
5. if too far to attack but target within ‘radius of escape’
a. Chase target (#3)
6. outside bounds go back to #1, 2
7. Evade if being attacked / might have to be somewhere in the beginning
a. set & attack target of not within sight
b. run away / cover / flee

 

A brief note I made myself since I had to go back to it before I learned it =)

  • Sequence / left to right will stop at failure, (Return failure or Return success tricks it) abort type LOWER PRIORITY means it will re evaluate everything
  • Parallel / runs multiple at the same time.
  • Selector / keep playing until one is success.
  • Repeater / repeats things
  • Perform interruption
  • Inverter

 

Old Code:

 


using UnityEngine;

namespace BehaviorDesigner.Runtime.Tasks.ThirdPersonController
{
[TaskDescription("Are We Dead?")]
// [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=111")]
[TaskCategory("KZ - NPC")]
[TaskIcon("Assets/Standard Assets/Other/Images/KZDevelopmentBlack.jpg")]
public class is_NPC_Dead_KZ : Conditional
{
// [Tooltip("A reference of NPC_Death_KZ, checks isDead, if dead then you know....")]
// public SharedGameObject targetGameObject;
// [Tooltip("isDead yes or not")]
[SharedRequired]
public bool isDead;

private NPC_Death_KZ npc_Death_script;

public override TaskStatus OnUpdate()
{
npc_Death_script = this.GetComponent<NPC_Death_KZ>();
isDead = npc_Death_script.isDead;
if (!isDead)
{
return TaskStatus.Failure;
}
return TaskStatus.Success;
} // on update

} // class ends here
} // namespace ends here

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NPC_Death_KZ : MonoBehaviour {

public bool isDead;

// Use this for initialization
public void SetPlayerDeath (bool deadNow)
{
isDead = deadNow;
} // setplayerdeath ends here
} // class ends here

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;

[TaskDescription("Get the player with its tag")]
[TaskCategory("KZ - Get Player")]
[TaskIcon("Assets/Standard Assets/Other/Images/KZDevelopmentBlack.jpg")]

public class GetSet_Player_KZ : Conditional {

public BehaviorTree behaviorTree;
// The tag of the targets
public string targetTag;
// Set the target variable when a target has been found so the subsequent tasks know which object is the target
public SharedGameObject target;

public override void OnAwake()
{
target = GameObject.FindGameObjectWithTag(targetTag);
behaviorTree = this.GetComponent<BehaviorTree>();
}

public override TaskStatus OnUpdate()
{
if(target != null)
{
// target.Value = Player;
behaviorTree.SetVariableValue("Player", target);
return TaskStatus.Success;
}
return TaskStatus.Failure; // if not
}

} // Class Ends here

 

</pre>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AC;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;

[TaskDescription("Is the current Player alive?")]
//[HelpURL("")]
[TaskCategory("KZ - AC Player")]
[TaskIcon("Assets/Standard Assets/Other/Images/KZDevelopmentBlack.jpg")]
//[Tooltip("A reference to the agent. If null it will be retrieved from the current GameObject.")]
public class Is_Player_Alive_KZ : Conditional {

public SharedGameObject targetGameObject;
private GameObject prevTarget;
public bool isDead;

public override TaskStatus OnUpdate()
{
// var target = GetDefaultGameObject(targetGameObject.Value);
var target = KickStarter.player.gameObject;
if (target != prevTarget) {
isDead = AC.GlobalVariables.GetBooleanValue(0, true);
prevTarget = target;
}

if (isDead == false) {
return TaskStatus.Success;
}
return TaskStatus.Failure;
// return isDead ? TaskStatus.Success : TaskStatus.Failure;
}

} // Class Ends Here
<pre>

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: