Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by taim_ar · Mar 16 at 08:01 PM · networkingmultiplayernavmeshagentbots

How to add Bots

i have a multiplayer game and its working just fine using Unet. now i wanted when someone create a room, he can control the bots amount in a room, i have tried to add a test Prefap to network manager spawnble prefap stuff and instantiate it but it didn't sync across players in game.

what i have in my mind is : 1_the bots take an slot in the room size. 2_the bots navmesh agent must run on host device only, then sync the transform.

well is it possible?

i have tried to at least instantiate it, but it didn't work at all, it only spawn on host not on client did any one have this problem before?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by taim_ar · Mar 26 at 03:00 PM

finally i got it!!!
to make it working you need to make sure you have Unet Game
1_make an new GameObject and add your stuff on it then add NetworkIdentity on it. DO NOT ENABEL ANY THING ON IT!!! alt text 2_Add you GameObject To you NetworkManager Registered Spawnable Prefabs alt text we have The AI Prefab Ready Now To Spawn it
"Btw i did it in my own way so you can do it in your way to "
Now to spawn it i made a separate script witch sits on player

 using UnityEngine.Networking;
 using UnityEngine;
 
 public class BotHandling : NetworkBehaviour //sits on player object
 {
     [SyncVar]
     public bool ThisIsTheHostPlayer = false;
 
     public GameObject Ai;
 
     void Start()
     {
         if (isLocalPlayer && isServer)
         {
             ThisIsTheHostPlayer = true;
             SpawnBots();
         }
         else
         {
             this.enabled = false;
         }
     }
 
     void SpawnBots()
     {
         int BotsNumber = 4;
         for(int i = 0;i<BotsNumber;i++)
         {
             Transform point = NetworkManager.singleton.GetStartPosition();
             GameObject bot = Instantiate
             (
                 Ai,
                 point.position,
                 point.rotation
             );
 
             //i am gona explain this wait for it
             bot.GetComponent<AI_State>().isOnHost = true;
 
             NetworkServer.Spawn(bot);
         }
     }
 }

Witch spawns the Bots
Now they are synced to all players
But they must move Right?
so add this to the AI

 using UnityEngine;
 
 public class AI_State : MonoBehaviour
 {
     public bool isOnHost;
 }

this is important for other scrips
Now we need the AI to move using NavMeshAgent
add NavMeshAgent Component to the Bot and add this script

 using UnityEngine.Networking;
 using UnityEngine;
 
 public class AI_Setup : NetworkBehaviour
 {
     [SerializeField]private Behaviour[] ComponentsToDisable;
 
     void Start ()
     {
         if(GetComponent<AI_State>().isOnHost)
         {
             EnableState(true);
             GetComponent<AI_Player>().PlayerSetup();
         }
         else
         {
             EnableState(false);
         }
     }
 
     void EnableState (bool ii)
     {
         for(int i = 0; i < ComponentsToDisable.Length; i++)
         {
             ComponentsToDisable[i].enabled = ii;
         }
     }
 }

this script disable components on client side but enable it on host side
i wanted my bots to work like this
now the components that need to be disabled is
1_NavMeshAgent
2_any script that moves the bot
Lastly add NetworkTransform To Sync Position and stuff
But i still have a problem when you close the room and re create a new room the bots don't move so its another problem to solve pls if someone have a solution to this please help
anyway thanks for all :)


image-2022-03-26-172918.png (8.8 kB)
2.png (24.1 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by PashDev · Mar 17 at 12:35 PM

You need to add a method who create the bots and spawn them, I don't know how you do it exactly in Unet

The method needs to run when the hosts start hosting ,

I guess that the bots can't leave the game if so you can add the the number of bots to the correct number of players connected

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image taim_ar · Mar 17 at 08:34 PM 0
Share

that is something that need a lot of testing but i will try to do it. thanks for your answer :)

avatar image PashDev · Mar 17 at 09:00 PM 0
Share

I think the hard part is code the actual bot, did you do it already?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

295 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UNET NavMeshAgent Sync Target Transform 0 Answers

Problem with UNET using NetworkManagerHUD 0 Answers

Unity UNET - Client unable to move 0 Answers

I'm using Unity MLAPI. Why does every client have id "0"? 0 Answers

Multiplayer Camera Rotation On Client 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges