playMaker

Author Topic: How can I change objects randomly with a button?[SOLVED]  (Read 266 times)

pharrr

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
How can I change objects randomly with a button?[SOLVED]
« on: September 15, 2017, 02:14:03 AM »
Hi,

I want to change the character's hat with the button.
There are four different hat objects.
When the button is pressed, the hat object disappears and the random new one
comes.
The positions of the hats are the same and depend on the skeleton of the character
It seemed easy at first, but it got mixed up as it progressed.

Thanks.
« Last Edit: September 20, 2017, 11:43:32 PM by jeanfabre »

tcmeric

  • Sr. Member
  • ****
  • Posts: 480
    • View Profile
Re: How can I change objects randomly with a button?
« Reply #1 on: September 15, 2017, 03:11:12 AM »
Can you show some screenshots of what you are doing? Or a video showing the states? This will make it easier for you to get some assistance.  8)

pharrr

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
Re: How can I change objects randomly with a button?
« Reply #2 on: September 19, 2017, 03:03:49 AM »
hat gif.
I want to do this.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2265
    • View Profile
    • jinxtergames
Re: How can I change objects randomly with a button?
« Reply #3 on: September 19, 2017, 03:19:00 AM »
Hi,
if it is in 2D maybe you can use swap sprite random.
you can find it on the Ecosystem

You can find many tutorials here to get started with Playmaker :)

pharrr

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
Re: How can I change objects randomly with a button?
« Reply #4 on: September 19, 2017, 04:29:34 AM »
This will be a simple 3d application. Thank you for your suggestion. I look at the tuttorials, but I have a limited time. Is there a more specific solution?

shinodan

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Shinozone
Re: How can I change objects randomly with a button?
« Reply #5 on: September 19, 2017, 04:45:20 AM »
Don't know how efficient this technically is but its what I have done in the past.

Create an empty Game object and call it "Hats" or something. Put it inside your player object and put all the hats inside it relative to where you want them to appear on your player, then disable them all.

Create your button and put an FSM on it, Create the same amount of states in it of your different hats.

Now make another State that sends a random event, make a bunch of events 1, 2, 3, 4 Ect, link them to your different hat states made earlier.

Now in the different hat states you can enable/disable different hats and make it return to start state and wait for another click!

Regards,
Dan


Thore

  • Playmaker Newbie
  • *
  • Posts: 47
    • View Profile
Re: How can I change objects randomly with a button?
« Reply #6 on: September 19, 2017, 05:57:40 AM »
1) Make sure the hats have a consistent anchor or mounting point. I'm not versed in 3D, but that would be the objects pivot. If that fits, skip step 2.

2) If you have no good pivots: Add Game Object, name it "Actual Hat". Give it a dot icon (inspector, top), so you see where it is. Take one good example hat mesh, and place it as a child. Now move it so that the point icon is where the hat is supposed to sit on the head. That's your anchor point. Later you do this for all hats, hence rename the "Actual Hat" to whatever the hat is, say "Cowboy Hat".

3) Next we define the place where the hats are mounted. Make a new game object, again, add a dot icon of a different colour, and call it "Mount Head". Next, drop one good example hat, say "Cowboy Hat" as child, and zero it properly. Now move the whole Mount-With-Hat contraption where it fits nicely. The pivot of the hat, the mount point and the place on the character model should now align. Because of this, you can now make any number of hats and when they are child and zero of the mount, they should fit perfectly.

4) Now, the drawing hats trick. Drop all hats under the mount (as prefab or as they are). This is now also the pool. In a more sophisticated system, the pool might be a separate object outside view, and you draw, parent, and set zero to mount.

5) All you need to do now is get a random hat, for example with get Random Child. I think there's also a method based on tags. Then activate this hat. Since you store the randomly drawn game object in a variable, you can use this to deactivate the object again, and then repeat with getting a new random object.

pharrr

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
Re: How can I change objects randomly with a button?
« Reply #7 on: September 20, 2017, 03:09:08 AM »
Don't know how efficient this technically is but its what I have done in the past.

Create an empty Game object and call it "Hats" or something. Put it inside your player object and put all the hats inside it relative to where you want them to appear on your player, then disable them all.

Create your button and put an FSM on it, Create the same amount of states in it of your different hats.

Now make another State that sends a random event, make a bunch of events 1, 2, 3, 4 Ect, link them to your different hat states made earlier.

Now in the different hat states you can enable/disable different hats and make it return to start state and wait for another click!

Regards,
Dan



Thanks everyone.

Your method worked :D
Thank you so much, Dan.