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 haroonalam · Oct 26, 2011 at 09:01 AM · c#javascript

Unable to check WALL to WALL check for tower defense game

I need help from you ppl again :) . I am making a 2D tower defense game. So far I did is I have made a 2d array which act as a grid for my game, placed towers on it, ran enemy and some dragging and tower firing stuff

Now I am facing a problem in tower placement logic. I want that any one path should be free for enemy, means that user must be unable to block a way by placing towers. for eg. if user places towers vertically on a map it must leave a space of one tower if all towers has placed in vertical way. or in any other way it must leave at least one space so that enemy can escape from that way. I think you have got what I am trying to say.

I have code a logic for it that, whenever tower has placed it checks in its all direction if there is a wall or tower, if there is a tower upwards it again call this function on that up tower until a wall comes, it returns 1 for upward wall and 5 for downward wall and return function(up/down tower) if there is a tower. here is the code:

 int checkCollision(tower)

{
if( there is a tower up) return checkCollision(up tower);

 if(there is a tower down) 
 return checkCollision(down tower);                                      

         ......all directions.....       

 if( there is a wall on UP )     
     return 1;

 if( there is a wall DOWN ) 
     return 5;

     ....all walls......

 return 0;   

}

Now what I want is, simultaneously check if there is a up wall and down wall OR check any other directions with any other possibility(like up-down, up-diagnol, down diagnol...so on) then do not let user to place tower as there should be one place left for enemy.

I am unable to check it, I mean my code tells that a wall is found but how can I check that a wall is found in one direction and a wall also found in another direction, I dont want to go into possibilities that

    if(checkCollision(tower) == 1 && checkCollision(tower) == 5) 
    "You cannot place"

I want something like:

    if( any combination of more than 2 wall found and there is entry/exit point in between)  //so it is wall to wall
     "You cant place"

I have also tired placing flags that true if there are wall on two sides(like up-down, up-diagonal etc. ) then dont let user to place tower but still I cant make it. Pls help me with this I am really stucked here.

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 syclamoth · Oct 26, 2011 at 09:15 AM 0
Share

I think you need a pathfinding algorithm for this stuff.

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

convert c# to JavaScript Problem 0 Answers

Send a variable from javascript to a C# Application 0 Answers

is Unity support socket javascpt client 1 Answer

Test if object is within collider bounds on start 0 Answers

Including a DLL in unity? 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