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
1
Question by femi96 · Jun 02, 2012 at 07:55 PM · moveturn-basedstrategyturn

Square Based Movement

I'm trying to create a game with a movement system like final fantasy tactics. I have made it so the code selects a unit and moves the cursor to the unit. Then you can move the cursor to select a place within the movement range of the unit, as long as the place is not occupied by another unit. The problem is that I don't know how to prevent the selection of a space behind a unit.

An example is this:

Green = Unit

Red = Enemy

Blue = Possible Moves

Yellow = Shouldn't be Possible moves

http://imgur.com/a/uIKsi

This is what I have done so far. I don't know how to check if a point is in the array because I can't figure out how to make Array.contains work in the Check function.

 function Check ()
 {
   for(var tile in tiles)
   {
     ntiles.Add(tile+Vector3.right+Vector3.right);
     ntiles.Add(tile-Vector3.right-Vector3.right);
     ntiles.Add(tile+Vector3.forward+Vector3.forward);
     ntiles.Add(tile-Vector3.forward-Vector3.forward);
   }
   for(var ntile in ntiles)
   {
     if(ntile == tiles)
     {
       print("contains");
       return;
     }
     tiles.Add(ntile);
   }
   print(tiles);
   movecheck = movecheck + 1;
   if( movecheck == mov)
   {
     BroadcastMessage("DoneCheck");
     return;
   }
   BroadcastMessage("Check");
 }
 function DoneCheck ()
 {
   for(var tile in tiles)
   {
     Instantiate(posmov,tile,Quaternion.identity);
   }
 }

This is Javascript

Any help is appreciated.

Comment
Add comment · Show 4
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 Oddeye · Jun 08, 2012 at 11:38 AM 0
Share

I am also interested in making a ff tactics/shining force style game. Not much of a programmer here, mostly 3ds max/zbrush/photoshop dude. If you are interested in combining our efforts let me know. (yeah i know im off topic here before everyone flames me, couldn't find femi on the forums).

avatar image femi96 · Jun 10, 2012 at 01:57 AM 0
Share

I'm glad that other people are interested in a FFT or Shining Force style game. At the moment, the only help I need is with the coding, but I will probably need more help down the road. Thanks for the offer :D

Edit: I'm on the forums now too

avatar image Oddeye · Jun 11, 2012 at 09:45 AM 0
Share

for sure! just hit me up if you ever need anything or want to work together. just out of curiosity, are you making a fantasy or futuristic rpg strategy game?

avatar image femi96 · Jun 11, 2012 at 11:55 AM 0
Share

Fantasy RPG

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by hathol · Jun 11, 2012 at 11:41 AM

I would store the possible fields in a collection and then use a recursive function starting from your player position to get all the walkable tiles. Would look something like this (just pseudocode):

 // a simple struct to hold information about your tile
 // use and extend as you see fit
 public struct Tile
 {
     bool isBlocked; // is the tile blocked (occupied by player/enemy)
     Tile[] neighbours; // the tiles that are directly reachable from this one (probably the 4 or 8 neighbouring ones)
 }
 
 //the list that will hold all your walkable tiles
 List<Tile> tileList = new List<Tile>();
 
 void CheckWalkables(Tile tile, uint stepsMoved)
 {
     //add the tile to the list
     tileList.Add(tile);
     if(stepsMoved < maxMovement) // we can walk another step
     {
         Tile[] neighbours = tile.neighbours; // get the neighbouring tiles
         foreach(Tile currentTile in neighbours)
         {
             //the tile is not blocked and not yet on the list
             if(!currentTile.isBlocked && !tileList.Contains(currentTile))
             {
                 //continue searching from there
                 CheckWalkables(currentTile, stepsMoved+1);
             }
         }
     }
 }


then you can start the search by calling

 CheckWalkables(tileYourPlayerIsOn, 0);
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 femi96 · Jun 11, 2012 at 12:05 PM 0
Share

This is a good idea but I don't know C#. I understand the basics of what this does so I'm going to try and replicate it in javascript if I can and get back to you.

avatar image femi96 · Jun 16, 2012 at 03:13 AM 0
Share

Updated the question

avatar image
1

Answer by jumble · Nov 11, 2013 at 11:21 PM

Preventing the selection of space behind the unit involves counting the 'path' to that space. For example, in your second picture, you can't get to the yellow spaces because the nearest one is four squares away and your green box clearly can only move three squares.

I handle it by computing how many squares of movement it would take to get there, then simply checking against my available movement. In your javascript there it'd be pretty easy to either prototype a method into "tile" or you could have a seperate method that takes a tile and the chosen unit and does the check.

If you need to get into pathing algorithms, there's the easy way or the fun way, but thats a different question.

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

7 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

How do I move objects in one executed turn? 1 Answer

My Gameobject position when i add child objects to it 0 Answers

Why can't I turn more then 45 degrees 0 Answers

Wanted: Good resource links that illustrate state machine design with specific reference to TBS game mechanics 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