0
\$\begingroup\$

Main question

How would I go about getting a movement system similar to the one they have in Mario Party only minus the dice roll?

Things I have researched

I have been studying the uses for ****arrays ,lists, for loops,onmousebuttondown**** but I want to make a movement system where the player has a limited amount of spaces, clicks a tile, and then moves to it. I kind of have a vague idea of how to go about this and I kind of know what I need......and I kind of don't....basically my brain isnt working and kind of hit a road block... Thus far all I have is the board it self... I understand how to make the highlights work when the cursor moves over the tile ..... but the major thing I can't figure out is how I should actually get the player to move after I click on the tile with the mouse button and have the player only move in a limited range.

Summary of things I'm looking for

Movement system kind of like mario party but minus the dice roll and instead of game board it would be on a grid

Players would only be able to move x amount of spaces both horizontally and vertically

Strictly for unity and please put any code in c#

Not looking for you to do my work but an example would be nice or at the very least point me in the right direction

Also, the board would be in a top down view but in 3d

I pretty much have an idea know what i need i just dont know the how to

Im not looking for a way to highlight the board just the turn based movement system itself. I thought I was clear with my question but maybe not as clear as I thought I was*

Picture of the grid on unity and an example of the turnbased movement system im looking for enter image description here

using UnityEngine;
using System.Collections;

public class GridScript : MonoBehaviour {

    public Transform cellPrefab;
    public Vector3 Size;
    // Use this for initialization
    void Start () {
        CreatGrid ();


    }

    void CreatGrid (){

    for (int x = 0; x< Size.x; x++) { 
        for (int z = 0; z< Size.x; z++) {
                Transform newCell;
            newCell = (Transform)Instantiate (cellPrefab, new Vector3 (x, 0, z), Quaternion.identity);
                newCell.name = string.Format ("({1},0,{1})",x,z);
                newCell.parent =transform;
                }
            }
        }
}
\$\endgroup\$
  • \$\begingroup\$ although your way of highlighting the tile looks and sounds better then the way i was gonna go about doing it I am mainly looking for how to move the player in a system like this.im not too worried about the highlighting still thank you @ratchetfreak \$\endgroup\$ – john smith Aug 29 '14 at 16:31
  • \$\begingroup\$ Is it the moving player from tile to tile to reach their goal that you need help with? \$\endgroup\$ – Malrig Feb 24 '16 at 15:51
  • 1
    \$\begingroup\$ This question is likely to be closed in its current format. I suggest you take this: "the major thing I can't figure out is how I should actually get the player to move after I click on the tile with the mouse button and have the player only move in a limited range" and make it the focus of your question, and remove all the waffling talk that distracts from this central point. We go for one question per post on this site. \$\endgroup\$ – Engineer Apr 27 '16 at 12:24
  • \$\begingroup\$ The short answer is: your movement function should take a desired x,y and only progress along one axis each update, to calculate the location, use A* or a similar path finding algorithm. \$\endgroup\$ – Joshua Hedges Jan 19 '17 at 19:43
1
\$\begingroup\$

Preface

Ok, I feel like this question has two main parts; one to do with code design and one to do with code implementation. It is important to understand that what you want is pretty much an entire gameplay loop and so will require a fair bit of code (more than a single script). I will try to help you with the design of the code but I think that help with the implementation will require other more focussed questions.

Different Scripts

I think this would require several scripts and I would split the behaviour into the following,

  1. GameManager - this guy is in charge of the game, he says whose turn it is and what happens (e.g. gold pick-ups, events etc),
  2. BoardManager - this guy knows everything about the board, he knows the positions of all the tiles and how they translate to game space, as well as the positions of all the players (probably most complicated script here),
  3. Player - this is the player and includes all their information e.g. health, gold etc,
  4. Mover - this is the script which actually moves the player from A to B, he will get the path from the BoardManager then move the player,
  5. Inputs - this gets the inputs from the player and passes it to the other scripts.

A Single Turn

This is what I would want to happen in a single turn,

  1. BoardManager calls function StartTurn() this
    • Tells Inputs that it is allowed to take inputs from the player,
  2. Inputs then gets the input from the player, on a click it calls GetMousePosition now this
    • gets the position of the mouse and sends it to BoardManager
  3. BoardManager uses this position to determine which tile the player is trying to move to. It then checks if the move is allowed,
    • if the move is allowed it tells the BoardManager the player is moving and Mover how to move the player,
    • if the move is not allowed it reports back the Inputs that it wasn't valid, GoTo 2.
  4. GameManager now knows the player is moving and tells Inputs to stop getting inputs from the player. Mover uses the directions from BoardManager to move the player around the board, once it finishes it tells the GameManager,
  5. GameManager knows the player has stopped moving, the players turn is now over and the GameManager calls EndTurn() this,
    • tells Inputs which player it now controls,
    • calls StartTurn() GoTo 1.

This is how I would design the gameplay loop along with the main scripts and some of their functions I would use. I hope this helps you with your game as well as pointing out the broad scope of your question. If you want any clarification on parts of my question feel free to ask and I can add more information.

\$\endgroup\$
0
\$\begingroup\$

Actually this is like any tile based movement from a turn based strategy game.

You can simply flood fill the tiles from the selected character to find which should be highlighted.

Psuedo code:

Set<Tile> getTilesInRange(Character character, int range){

    Set<Tile> highlighted;
    highlighted.add (character.tile);
    Set<Tile> waveFront;
    waveFront.add (character.tile);
    for(int i = 0; i < range; i++){
        Set<Tile> nextWave;
        foreach(Tile tile in waveFront){
            foreach(Tile neightbour in tile.getNeighbours()){
                if(neightbour in highlighted) continue;

                highlighted.add(neighbour);
                nextWave.add(neighbour);
            }
        }
        waveFront = nextWave;
    }
    return highlighted;
}
\$\endgroup\$
-1
\$\begingroup\$

1) Use Breadth First Search (BFS) to calculate the path http://en.m.wikipedia.org/wiki/Breadth-first_search

2) Highlight path

3) Move the object

Pathfinding: http://theory.stanford.edu/~amitp/GameProgramming/AStarComparison.html

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.