playMaker

Author Topic: Select more than one object.  (Read 3239 times)

masterr

  • Playmaker Newbie
  • *
  • Posts: 17
Select more than one object.
« on: May 15, 2016, 07:57:39 AM »
Hi. Lets say i have 5 objects and i need to take some of them and put in the basket. How can i achieve this with playmaker.  How to select more than one object. It can be rectangle selection like in Real time strategy games or something else.  Help please.

Zeldag

  • Full Member
  • ***
  • Posts: 198
Re: Select more than one object.
« Reply #1 on: May 15, 2016, 09:26:31 AM »
Hi,

This question is hard to answer.

I assume you mean during gameplay? :)

How do you currently select one object? I may be able to give you a workable solution from there.

masterr

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Select more than one object.
« Reply #2 on: May 16, 2016, 05:28:07 AM »
Hi. Thanks for trying help.  Currently im selecting with mouse pick event and then storing it in a game object variable. Then moving this variable. But i cant figure out how to do it with multiple objects. The ideal solution that i would like to have is to be able to draw a rectangle and the objects inside of this rectangle would be selected and stored in some kind of variable or i dont know :)

Chizzler

  • Junior Playmaker
  • **
  • Posts: 67
Re: Select more than one object.
« Reply #3 on: May 16, 2016, 01:01:00 PM »
My approach would be to first get the starting point to draw the rectangle. First I'd need to setup a state listening for "Mouse Button Down" which transitions into a state which grabs the Mouse X & Y Positions and translates that to world space and Activates our Selection Box. We'll transition into a new State waiting for "Mouse Button Up" whilst grabbing the mouse X & Y Positions every frame and translating them to world space. We'll revisit this state in a moment and add more stuff, but first, I should explain what our "Selection Box" is made of.

Our selection box prefab is a meshless 3d cube with a trigger attached and a pivot point in the corner, rather than the centre. It needs an FSM attached checking for Entry and Exit events against Units (have them tagged). When a unit enters the trigger, add it to an array. When it leaves, remove it from the array.

Now we know what the box is, we'll go back to the state grabbing the Mouse position whilst waiting for the player to release the mouse button.
We can use the Get and Set Property Actions to adjust the size of the selection box's collider based on the mouse position. Do this each frame whilst waiting for "Mouse Button Up"

When the player releases the mouse, it'll transition to a new state which Deactivates the selection box game object. You're left with an array of Units which you can loop through with your commands.



I reccommend first getting to grips with Arrays before tackling the selection box side. So when you click a unit to select it, instead of just saving it as a game object variable as you have done already, also save that game object variable to an Array. When it comes to issuing commands, use the "Array get Next" action to loop through it and apply the command to each unit.
« Last Edit: May 16, 2016, 01:08:38 PM by Chizzler »

masterr

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Select more than one object.
« Reply #4 on: May 27, 2016, 01:38:54 PM »
Thank you Chizzler for this great explanation. As you say i need to learn more about arrays. I never used them before. I guess it is really helpful with this kind of jobs. Thank you again.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Select more than one object.
« Reply #5 on: May 27, 2016, 08:22:12 PM »
Hi,
Here you can find some array maker tutorials

masterr

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Select more than one object.
« Reply #6 on: May 29, 2016, 04:09:07 AM »
Thanks a lot djaydino