Author Topic: TNet and AI  (Read 3689 times)

wolkovik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
TNet and AI
« on: December 07, 2013, 12:20:43 PM »
Hey guys
I've been reading a lot of topics but I didnt find any info about how to manage AI in unity with TNet.
Can somebody please direct me in a right direction about AI management? If AI is calculated at each connected client and then synched (i dont know about this option - what if a client tempor. disconnects...?) or somehow built in in the launched TNET server or something like that?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet and AI
« Reply #1 on: December 07, 2013, 04:16:38 PM »
If you normally do AI in some Update() function of a script attached to your NPCs, make the script derive from TNBehaviour instead of MonoBehaviour, attach a TNObject to work with like you would with any sync'd object, and in the Update function exit early if (!tno.isMine).

Then instead of setting local values using your AI logic, send them to everyone using RFC calls.

wolkovik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: TNet and AI
« Reply #2 on: December 07, 2013, 04:51:34 PM »
Ok, it seems logical. Thanks  :)

CastorHolyday

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: TNet and AI
« Reply #3 on: January 14, 2014, 03:52:03 PM »
"and in the Update function exit early if (!tno.isMine)."

means if(tno.isMine == false) { //dont do stuff inside unless tno isMine returns true } ?

I don't understand this part, I mean why ! the AI is supposed to belong to none but in the same time everyone can interact with them, a quick explanation with a simple exemple say like from StarCraft Online with 2 players & 1 AI would be welcomed, if you don't mind.

Thanks.
« Last Edit: January 14, 2014, 05:01:48 PM by CastorHolyday »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet and AI
« Reply #4 on: January 14, 2014, 07:00:10 PM »
Exiting out early means this:
  1. void Update()
  2. {
  3.     if (!tno.isMine) return;
  4.     // ...do actual game logic, including AI logic
  5. }

CastorHolyday

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: TNet and AI
« Reply #5 on: January 14, 2014, 07:12:27 PM »
But ! which script is that ? a special script for the AI on the AI Object or on the player script I'm confused.

I think i'm thinking server Autho while you are talking about a p2p implementation.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet and AI
« Reply #6 on: January 14, 2014, 10:06:55 PM »
The script where AI logic happens. It should only happen on one of the players -- whoever owns the object.

CastorHolyday

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: TNet and AI
« Reply #7 on: January 15, 2014, 05:07:49 AM »
I got it thanks.