Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Grenkin · Nov 20, 2017 at 08:20 PM · movementupdatetileboardgame

BoardGame like movement. From tile to tile movement

Hi, I am learning Unity by porting board game to pc. Issue: Player can move by tiles on particular distanse. I would like to make this movement to be step by step from tile to tile. Right now there is code to find path and to get array of tiles that player will go trough. I've tried to make it in CustomCharacterController by it is still moving imidiatly to final tile.

 [UsedImplicitly]
     public class CustomCharacterController : MonoBehaviour {
 
         [SerializeField]
         private float _moveSpeed = 0.5f;
         private bool _isMoving = false;
         private Vector3 _nextTarget;
 
         [UsedImplicitly]
         private void Start() {
 
         }
 
         [UsedImplicitly]
         private void Update() {
         }
 
         public void MoveToBySteps(Square[] characterPathToTarget) {
             for (int i = 1; i < characterPathToTarget.Length; i++) {
                 _isMoving = true;
                 Square next = characterPathToTarget[i];
                 Coordinates? nextCoordinates = next.ParentTile.FindSquareCoordinates(next);
                 if (!nextCoordinates.HasValue) { continue; }
                 float targetX = nextCoordinates.Value.X + next.ParentTile.X + 0.5f;
                 float targetY = nextCoordinates.Value.Y + next.ParentTile.Y + 0.5f;
                 _nextTarget = new Vector3(targetX, targetY, 0);
                 while (_isMoving) {
                     Move();
                 }
             }
         }
 
         private void Move() {
             float step = _moveSpeed;
             transform.position = Vector3.Lerp(transform.position, _nextTarget, step);
             if ((transform.position - _nextTarget).magnitude <= 0.05f) {
                 _isMoving = false;
             }
         }
     }

Also here can be found other bits of code: here

Character CharacterView

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by MaxGuernseyIII · Nov 20, 2017 at 09:36 PM

I would look in to animation. Create an animation and and animation controller. Attach them to your tile. Use the animation editor to make the movement look as smooth as you want. Then have your movement controller tell the animation where to move the tile from and to and initiate an animation.

The problem of making it move through multiple squares in sequence can be handled with a coroutine. loop through each of the spots to which you want to hop but yield while the animation for movement is playing.

Information on animations and coroutines are available in the manual.

Comment
Add comment · Show 4 · 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 Grenkin · Nov 20, 2017 at 10:10 PM 0
Share

Can I somehow do this without animations? Do I really need it in order to move? This is just simple move A-B-C-D $$anonymous$$y issue is that visually it is just A-D and momentally.

avatar image Bampf Grenkin · Nov 21, 2017 at 02:48 AM 0
Share

$$anonymous$$ax's advice is good, whether or not you are using animations. Another way to say what you want is: move to first square, wait N seconds, move to next square, wait N seconds... You have written the movement code but you aren't waiting so the player sees nothing.

The good news is, it will be straightforward to turn $$anonymous$$oveBySteps into a co-routine. After every step your coroutine just needs to yield for N seconds, and then your loop will continue. There's a little more to it than that, but not much more.

avatar image MaxGuernseyIII Grenkin · Nov 21, 2017 at 03:20 AM 0
Share

I thought part of the problem was you wanted the pieces to move smoothly from one space to another. If you don't want that, you don't need animations.

If you do want to do it, you can still hand-roll the smooth movement but you would just be reinventing animations at that point.

avatar image Grenkin · Nov 21, 2017 at 06:34 AM 0
Share

O$$anonymous$$, thanks. Will try to make whole $$anonymous$$oveToBySteps as coroutine as suggested.

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

108 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

Related Questions

An arrow pointing from one hexTile to another hexTile 0 Answers

Object Squeezing Between Tiles 0 Answers

Problem using a position determined from onTrigggerEnter in Update 2 Answers

Creating a 2D Movement Grid 0 Answers

Raycast based tile navigation 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