Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Fuhans · Dec 12, 2013 at 06:46 PM · c#aipathfindturn based

Stuck when want to make the AI in Turn-Based Strategy Game

Hai everyone, i already can make the movement grid via pathfinding and avoid obstacles for the player. Right now, i want to make the AI move itself based on the how many movement grid and the action point (just like the player does). But, i don't know how to do it.. Right now, i just able to make the character move to the position (but it is not follow the pathfinding, this character suppose to be the AI).. I am stack at this and try to solve this problem, but couldn't. Could you guys help me out? Thanks.

Here is the code that i mention in the above (can make the character which is suppose to be AI to move to the position, but it not follow the pathfinding):

 using UnityEngine;
 using System.Collections;
 
 public class AIPlayer : Player
 {
     void Awake()
     {
         moveDestination = transform.position;
     }
 
     // Use this for initialization
     void Start()
     {
         ColorChanger();
     }
     
     // Update is called once per frame
     void Update()
     {
     
     }
     
     
     public override void TurnUpdate()
     {
         if (GameManager.instance.currentPlayerIndex == 5)
         {
             if (Vector3.Distance(moveDestination, transform.position) > 0.1f)
             {
                 transform.position += (moveDestination - transform.position).normalized * moveSpeed * Time.deltaTime;
 
                 if (Vector3.Distance(moveDestination, transform.position) <= 0.1f)
                 {
                     transform.position = moveDestination;
                     actionPoints--;
                 }
             }
 
             else
             {
                 moveDestination = new Vector3(2 - Mathf.Floor(GameManager.instance.mapSize / 2), 1.5f, -2 + Mathf.Floor(GameManager.instance.mapSize / 2));
                 GameManager.instance.NextTurn();
             }
         }
 
         base.TurnUpdate();
     }
 
     public override void TurnOnGUI()
     {
         
     }
 
     public override void ColorChanger()
     {
         base.ColorChanger();
     }
 }

Here is the link video for the game:

http://www.youtube.com/watch?v=eo7DzbBPQBs&feature=youtu.be

Comment
Add comment · Show 1
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 Hoeloe · Dec 12, 2013 at 09:49 PM 0
Share

Just a quick tip: it's "stuck", not "stack". Worth getting this right, particularly in this context, as "stack" is a type of data structure, and a feature of most execution environments, which could be quite confusing.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by demented_hedgehog · Jan 28, 2015 at 06:30 AM

Late answer .. but I'm looking at this myself so I'll write what I know down for others. AI is a big topic.

First, I'd have a look at something like RAIN (free from the asset store) to see whether it does what you want.

Failing that, take a look at the path finding algorithms: A*, Dijkstra's and floodfill. There's code that does this already you can download. A fellow called UnityChat has got a good tutorial for using the A* algorithm in turn based strategy games on youtube.

Then you may want to build some AI on top of your raw pathfinding with some kind of planning code. (That's as far as I've got so far :)

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

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

19 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How can I more optimize My AI Script 0 Answers

How can I get a character to patrol and follow terrain? 1 Answer

Health not being subtracked. 1 Answer


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