Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Npc behaviour Rudimentary setup #78

Merged
merged 49 commits into from
Jan 27, 2022
Merged

Npc behaviour Rudimentary setup #78

merged 49 commits into from
Jan 27, 2022

Conversation

TheUQGuy
Copy link
Contributor

@TheUQGuy TheUQGuy commented Oct 6, 2021

This is a basic NPC script along with a character in scene for people to work with. I'll be adding/pulling a character state system in place tomorrow for better management. I have a better plan to mannage character states (Enemy, Follow, Idle, Teamate etc) down the line but this should allow people to tinker with the current system tonight while add to it tomorrow. Any feedback greatly appreciated.

TheUQGuy and others added 9 commits September 27, 2021 22:57
Added a folder specifically for NPC's And created a very rudimentary NPC script. With a dialogue option
Updated Agent to include a isEnabled field. That prevents Root from running in update if disabled
Made a test NPC with a rudimentary behaviour tree.
It still requires that behaviour added in the behaviour tree but it will do for now
It is a simple script for now. I'd hope to program the movement scripts into generic behaviour nodes later.

Still need to add:
-Collision detection and avoidance
-A follow path function.
Reformatted the old scripts to work with the new node system, created a basic follow player behaviour tree, and created a TestNPC companion in scene
This is the scene with the added testNPC
Copy link
Member

@JadenBalogh JadenBalogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff so far; I added some comments on specific areas that could be refactored (potentially in the future once further features are added).

The main thing to look into would be the object hierarchy and what classes extend what. We talked about it already in Discord but as a summary, there's kinda three distinct parts to note for this type of gameobject:

  1. Actor (and subclasses): Actors are basically any entity which should engage in combat / have a lifecycle.
  2. NPC: These are an extension of Interactable and are basically a fancy interactable that uses dialogue graphs.
  3. Agent: Agents include any non-player object that needs a custom behaviour cycle.

I would ensure your NPCs have at most one of each of these types, depending on what their needs are. (I noticed while going through this that Interactable actually extends Entity atm, which probably doesn't make sense, so that may be something to refactor at some point also.)

Assets/Scripts/Game/NPCs/BaseNPC.cs Outdated Show resolved Hide resolved
Comment on lines 49 to 66
public void TurnIntoEnemy(){
//Change to enemy Layer;
gameObject.layer=LayerMask.NameToLayer("Enemy");

//Doesnt if this doesn't have Enemy Script will add it
if(gameObject.GetComponent<Enemy>()==null){
gameObject.AddComponent<Enemy>();
}
else{
gameObject.GetComponent<Enemy>().enabled=true;
}
//TODO add AttackBehaviour in BehaviourTree
}

public void TurnIntoCompanion(){
//TODO Make Follower movement, interactable
npcCollider.enabled=false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually I'm planning to have a "faction" system that we can use to help determine interactions between various actors (i.e. who is hostile to who). Maybe when we have that type of system, we'll be able to refactor this part into a generic ChangeFactionNode behaviour.

Adds a node that forces the dialogue with the player instead of having that in the NPC behaviour script
Noticed that checkRangeNode implemented what I wanted already (may need to add both min and max values to checkRange later) but it accomplished what I want for now.
@JadenBalogh JadenBalogh self-assigned this Nov 10, 2021
@JadenBalogh
Copy link
Member

@TheArchitect4855 This PR is now ready for review! Unfortunately a bunch of sub-features and bug-fixes are tangled into it, so there's a lot to pull apart. Main things to focus on are:

  • patrol behaviours
  • forced dialogue behaviours
  • enemy <-> npc conversion logic
  • dynamic inspector link fields a.k.a. DILF (as seen in the CompareNode for example)
  • various bug fixes for dialogue and behaviour trees

@JadenBalogh JadenBalogh linked an issue Dec 8, 2021 that may be closed by this pull request
Copy link
Contributor

@TheArchitect4855 TheArchitect4855 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at all those chickens! That's a lot of changes.

Looks good; I'm excited to see all of this new NPC stuff in action.

@JadenBalogh JadenBalogh merged commit ff76bec into dev Jan 27, 2022
@JadenBalogh JadenBalogh deleted the npc-behaviour branch January 27, 2022 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment