Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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 LoneWolfe007 · Sep 13, 2016 at 01:58 AM · c#spritegrid based gamedungeon

Grid based movement, sprite change to simulate movement

Hello,

I am in the process of creating a first person dungeon crawler and I have run into an issue. I am pretty new to the concept of coding so I am sure there is a much easier way to do what I have done but I wasn't sure what the correct coding process was.

Anyway, I am creating a first person dungeon crawler that looks like this:

alt text

My idea is in a 9 square grid with each grid square having 4 pictures (North, East, South, West.)

alt text

Here is the code I use to change the pictures to depict the feeling of walking:

     public Sprite One_North;
     public Sprite One_East;
     public Sprite One_South;
     public Sprite One_West;
     public Sprite Two_North;
     public Sprite Two_East;
     public Sprite Two_South;
     public Sprite Two_West;
 
     public Image gameplayImageTransition; 
     private DirectionDetection directionDetection;
 
     public string currentTileNumber;
     public string currentDirection;
     public string currentTileAndDirection;
 
     // Use this for initialization
     void Start () {
         currentDirection = "North";
         currentTileNumber = "Two";
         gameplayImageTransition.sprite = Two_North;
     }
     
     // Update is called once per frame
     void Update () {
         if(Input.GetKeyDown(KeyCode.UpArrow)){
             Debug.Log ("Up Arrow");
             UpdateWalkPathForward ();
         }

         if(Input.GetKeyDown(KeyCode.LeftArrow)){
             Debug.Log ("Left Arrow");
             UpdateWalkPathLeft ();
         }
     }
 
     void UpdateWalkPathForward(){
         if (currentDirection == "West") {
             ConvertCurrentTileNumberToInt ();
             int curTileDummy = System.Convert.ToInt32 (currentTileNumber) - 1;
             currentTileNumber = System.Convert.ToString (curTileDummy);
             ConvertCurrentTileNumberToString ();
             gameplayImageTransition.sprite = (Sprite)this.GetType ().GetField (currentTileNumber + "_West").GetValue (this);
         } else if (currentDirection == "East") {
             ConvertCurrentTileNumberToInt ();
             int curTileDummy = System.Convert.ToInt32 (currentTileNumber) + 1;
             currentTileNumber = System.Convert.ToString (curTileDummy);
             ConvertCurrentTileNumberToString ();
             gameplayImageTransition.sprite = (Sprite)this.GetType ().GetField (currentTileNumber + "_East").GetValue (this);
         }
     }
 
     void UpdateWalkPathLeft(){
         if(currentDirection == "North"){
             currentDirection = "West";
             gameplayImageTransition.sprite = (Sprite)this.GetType().GetField(currentTileNumber + "_West").GetValue(this);
         }else if(currentDirection == "West"){
             currentDirection = "South";
             gameplayImageTransition.sprite = (Sprite)this.GetType().GetField(currentTileNumber + "_South").GetValue(this);
         }else if(currentDirection == "South"){
             currentDirection = "East";
             gameplayImageTransition.sprite = (Sprite)this.GetType().GetField(currentTileNumber + "_East").GetValue(this);
         }else if(currentDirection == "East"){
             currentDirection = "North";
             gameplayImageTransition.sprite = (Sprite)this.GetType().GetField(currentTileNumber + "_North").GetValue(this);
         }
     }
  
     public void ConvertCurrentTileNumberToInt(){
         if (currentTileNumber == "One") {
             currentTileNumber = "1";
         }else if (currentTileNumber == "Two") {
             currentTileNumber = "2";
         }
     }
 
     public void ConvertCurrentTileNumberToString(){
         if (currentTileNumber == "1") {
             currentTileNumber = "One";
         }else if (currentTileNumber == "2") {
             currentTileNumber = "Two";
         }
     }
 }
 

So basically you start at Two_North (tile two, facing North) and in my example you press the left arrow which changes the pictures from Two_North to Two_West. Then when you press the Up arrow it will switch the picture from Two_West to One_West like you were walking one square up.

One of the main things I have run into is getting the math to work. So far it works okay but my issue is that if I am on tile four and I'm facing west and press up on the keyboard I will jump from Four_West to Three_West which should not happen. Instead of jumping to the top of the grid the player should just stand in Four_west and not move anywhere (basically like running into a wall.)

If anyone has any tips for me that would be amazing, at this point I am stuck trying to figure out what to do with this. Thank You for your help.

untitled.png (8.6 kB)
town-beta-2e.png (4.0 kB)
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

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

238 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

Related Questions

creating a 2d peeling system in unity 0 Answers

When all of the enemies in a room dies the doors dont open. 0 Answers

Help with Instantiation and Sprite changing lag 0 Answers

Is it possible to create a texture that hides a specific texture? 0 Answers

Creating rooms and corridors by Random dungeon generation 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