Hi
Need some help . I want 3d object to move around the outside of a game board (like most board games e.g monopoly)
The movement is determined by a shake of a dice.
I have just downloaded itween … how can this help?
I would appreciate all help inc. links to other discussions
@Jo_Jo
In no shape, way, or form am I an expert, but I can talk theory. In theory, all of the movement would be done automatically after the dice have been cast.
For an example, let’s say we have a rectangular 10x10 board with the player starting at the bottom left at (10,0). Once the player reaches the top left (0,0), rotate the object 90 degrees for continued movement. When the player reaches the top right (0,10), rotate 90 degrees again and so on and so fourth.
Another way I suppose would be to create a matrix that the dice sifts through for the player position…
It looks like you already got some reasonable suggestions, but most likely you’ll want to create a container that stores the positions of the squares/locations on the board, and then assign those positions as appropriate to the ‘position’ property of the transform of the game object representing the game piece. You’ll then probably want to smooth things out using interpolation (e.g. manually, using iTween, etc.).
Could you specify what part of the process you’re unsure of?
Hi Jesse
Thanks
The parts I need help with are moving appropriate no. of squares and turning corners.It must follow the square board and not cut corners
Basically if anyone has got some java code that I could adapt/look at …I would be grateful
This is basically the same reply that I always give to this sort of question, but if you’re looking for complete, working code, you might try the Collaboration forum (rather than the support forums) and see if you can get a programmer involved in the project.
Some people don’t mind offering complete code solutions in the support forums, but others take the view that the support forums are for helping people solve their Unity-related problems, rather than simply solving their problems for them (especially move involved problems such as this one).
That said, I’d be happy to offer some tips (as would others, I’m sure). Let me start by asking this: Is the board arrangement strictly linear? That is, are all the squares in a linear sequence (or loop), or are there branches and multiple ways that the pieces can go?
(Also, why are you asking for Java code? Java isn’t one of the languages that Unity supports…)
Oh, none taken We do get a lot of people here simply asking for completed, working code, so I may have misinterpreted your post.
Anyway, a linear, looping sequence should be pretty easy to handle. Most likely, the first thing you’ll want to do is store the position of each square (its center, most likely) in some sort of container, such as an array or List. You could assign the coordinates by hand, either in code or in the inspector, or you could generate them procedurally. The important part is that you end up with a container containing the centers of each square, in sequence.
For each piece, you’ll need an integer index indicating which square it’s currently on. When you want to advance a piece N squares, you can do something like this (pseudocode, untested):
for (int i = 0; i < numSquaresToMove; ++i) {
piece.currentSquare =
(piece.currentSquare + 1) % totalNumberOfSquares;
}
That covers the basics. In practice, you’ll probably want to animate the movement of the pieces from square to square, which’ll complicate things a little, but I’d recommend getting the basics working first before worrying about that.
@Jo_Jo
Here is some pseudo-code for you to look at to get you on the right direction.
Scene: monopoly-style board 10x10 in size. Bottom left is starting point located at (10,0) and the player moves clockwise around the board.
get diceValue; // the total value of the dice
movementNumber = diceValue; // how many movements remaining
// while the player can move
while movementNumber >= 0
{
move forward one unit;
// if the player reached a corner...
if playerPosition = (0,0) || playerPosition = (0,10) || playerPosition = (10,0) || playerPosition = (10,10)
{
rotate player 90 degrees
}
movementNumber--;
}
@The OP: I wouldn’t recommend doing it that way. For something like this there’s really no reason to introduce any operations that might suffer from numerical error, which includes the coordinate comparisons, player movement, and rotations in the above pseudocode. (Maybe the above code is intended to work with integers, but the approach is still needlessly complex, IMO.)
I would instead recommend using the method I described earlier, as it’s deterministic and will not suffer from numerical error, but (once you add animation effects) will still result in smooth motion.