playMaker

Author Topic: How to move an object according to dice  (Read 3433 times)

smz

  • Playmaker Newbie
  • *
  • Posts: 2
How to move an object according to dice
« on: March 15, 2016, 02:19:06 PM »
Total newbie to Playmaker here and so far I've been playing around with different actions and learning the basics for a few days. I wanted to try something that I first assumed would be quite simple mechanic but turned out to be more complex I imagined (for me at least).

So what I would like to do is have my player object move forward on my game board according to randomly generated value of a dice (like in a typical board game - throw a die - move ammout x).

So far I only have this:
  • Random Int action that stores the int value into DiceValue variable
  • CurrentPosition variable set to 0 int
  • Int Add action that takes the value of my CurrentPosition variable and adds the value from DiceValue variable to it

And my idea was to set an Int value variable to each object the player can move to and then somehow set my players position over the correct object but I just can't figure out how to accomplish this, which lead me to think that my Int approach with this is completely wrong.

So could somebody help me and guide me what would be the preferable way to do something like this, e.g. what actions should one use, different kind of variables like vector3?

All tips are appreciated, thank you!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to move an object according to dice
« Reply #1 on: March 16, 2016, 03:15:08 AM »
Hi,

 You are on the right track.

what you'll need is an "interface" between your board physical slots and your Players position.

-- for a given index of slot, what is the 3d position
-- for a given player what is the delta movement to move

the complexity here is about the path itself,
--is the board round, square or in various shapes?
--how will your player move along that board? is it a path or series of cubes.
-- How does the player move? is it "transported" instantly, or moved nicely with a small time.

All these questions will shape how you will go from the dice integer to a final movement of the piece.

Bye,

 Jean

smz

  • Playmaker Newbie
  • *
  • Posts: 2
Re: How to move an object according to dice
« Reply #2 on: March 17, 2016, 05:15:57 PM »
Thank you for the reply! Good to know I'm on a right path.

My board so far consist a few platforms objects in different distances and heights of each other. The movement itself would be animated, having the object hover to the destination so not a simple transportation, even though just being able to transport the player object to the desired platform according to the dice value would be enough at this point.

But my biggest problem is how to figure out a way to make the game understand which Int equals which Vector3 value of each platform. I basically have a working dice of which random Int value combined with the Int value set for the player object position equals the correct Int value of the destination platform.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to move an object according to dice
« Reply #3 on: March 18, 2016, 02:12:06 AM »
Hi,

 several options available to map your slot index with a vector3 position.

-- If you are using PlayMaker 1.8 you can create a an FsmArray with all the vector3 position, and you use the index of the array to get to a specific Vector3. Simple and effective

-- If you are not using PlayMaker 1.8, use ArrayMaker. It's a fully feature system for working with lists and hashtables. so you'll have two ways, one using an ArrayList (  like an FsmArray basically), or using a hashtable, where the key will be your index, and the value will be your vector3 position.

-- maintain dummies that represent each slot position, and name them properly with a convention like "Slot x", so you would have "Slot 1", "Slot 12", and simply use the action "Find GameObject" to get a reference of that dummy, get it's position, or use it as a target for your tween directly. MAKE SURE you use a tag 8 for example "slot", and when using "Find GameObject", that you filter by tag, else it will impact performance, finding object in the hierarchy is not effective ( a Unity limitation), and using tag will improve greatly the search performances.

There are few more ways, but since you are starting with all this, those would be the main ones that you should each master and understand fully. Being able to use one of these solution will help you in the long run to create more and more complex features. The last one if the most direct one without having to learn too many new concepts ( list, arrayList, hashtable are advanced concepts, difficult to grasp if non coder).

let me know how it goes,


Bye,

 Jean

NodeEncounter

  • Playmaker Newbie
  • *
  • Posts: 7
Re: How to move an object according to dice
« Reply #4 on: April 27, 2020, 07:27:32 PM »
Is there anymore input or feedback someone can provide for this inquiry?

I also created a very basic structure for "roll dice" that provides a result which gets subtracted with every movement. I'm having with the FindGameObject by filtering by tag recognizing all available movement spaces.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to move an object according to dice
« Reply #5 on: May 13, 2020, 01:39:29 AM »
Hi,

 Do you have issues deducing the name of the potential slots or do you have issues with the action itself?

 you need to maintain a indexing of your current slot using something like X and Y representing the slot position in a grid. so [3,4] means third row, fourth column for example.

 now if you want to move left, you need to go to [4,4], right? so you can by convention expect that a gameobject  "slot 44" is in your scene with a tag "Slot", search for it and move there.

Let me know if this is not where you struggle.

Bye,

 Jean