playMaker

Author Topic: Placing game objects on a grid  (Read 3204 times)

coffeeANDsoda

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
Placing game objects on a grid
« on: May 01, 2016, 09:58:06 PM »
So I have 1 object that creates prefabs, and that prefab moves towards a empty game object. Here's my problem. When I want the prefab to move towards the nearest game object it only moves towards the first empty object.

Bare in mind there are five empty objects that act as a grid.

How could I get a prefab to move towards the nearest object that the player places it.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14400
  • Official Playmaker Support
    • View Profile
Re: Placing game objects on a grid
« Reply #1 on: May 01, 2016, 11:13:57 PM »
Hi,

You could loop through all your empty slots, and record the one that is the closest in distance.

To keep a list of empty slots, use ArrayMaker or if you have PlayMaker 1.8, use FsmArray variables.

 Bye,

 Jean

coffeeANDsoda

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
Re: Placing game objects on a grid
« Reply #2 on: May 01, 2016, 11:31:36 PM »
Hi,

You could loop through all your empty slots, and record the one that is the closest in distance.

Aside from making a manager, what about having the manager identify where a prefab game object moves towards. What about the Array List Contains action. I thought about raycast actions for each prefab cube, but would that mean I'd have a make multiple global transitions for it? Or some sort of global variable?

When I think of having the prefab cube object moving towards a empty game object point, wouldn't there have to be raycasting?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14400
  • Official Playmaker Support
    • View Profile
Re: Placing game objects on a grid
« Reply #3 on: May 01, 2016, 11:50:44 PM »
Hi,

 Raycasting is really to find out what's in front of you, not necessarly to get an overview of what's around you, that would be really cumbersome is not efficient.

If you have less then a dozen of potential slots to check, a loop is totally fine especially since it's a discrete computation, you would not do that within the game loop.

also, you can turn it on its head, and have the empty slot finding out its distance with the target, and fill up a list, then you don't need to centralize it and you end up with a more object oriented design which is preferable.

Bye,

 Jean

Bye,

 Jean

coffeeANDsoda

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
Re: Placing game objects on a grid
« Reply #4 on: May 05, 2016, 11:09:35 PM »
If you have less then a dozen of potential slots to check, a loop is totally fine especially since it's a discrete computation, you would not do that within the game loop.

also, you can turn it on its head, and have the empty slot finding out its distance with the target, and fill up a list, then you don't need to centralize it and you end up with a more object oriented design which is preferable.

What don't understand is how would this apply to using a manager with a proxy list if I have about 5 empty objects acting as a point or place for a prefab object to move towards? And when you mean by slots for a empty object manager, would that have a relation to a list added for the empty object points.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14400
  • Official Playmaker Support
    • View Profile
Re: Placing game objects on a grid
« Reply #5 on: May 06, 2016, 06:30:10 AM »
Hi,

 yes, have all your "place" targets sending events to a manager like "HAS COME IN RANGE", "HAS LEFT RANGE", and the manager receiving this can maintain a list of what object is in range.

 better, I would simply send it to the gameobject that triggered in the first place your "place" Collider, and talk to it directly via an event like "I AM IN RANGE"

you essentially are creating a layer of indirection for TRIGGER ENTER and TRIGGER EXIT. isn't it the same thing in the end that you want to achieve?

Bye,

 Jean

coffeeANDsoda

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
Re: Placing game objects on a grid
« Reply #6 on: May 09, 2016, 11:51:28 PM »

better, I would simply send it to the gameobject that triggered in the first place your "place" Collider, and talk to it directly via an event like "I AM IN RANGE"

you essentially are creating a layer of indirection for TRIGGER ENTER and TRIGGER EXIT. isn't it the same thing in the end that you want to achieve?

What about with a manager that has two global transition events, one that is suppose to send a global transition to the prefab with a fsm that moves towards the points?

Last I checked, I set a manager with a standard START transition and a custom global transition to either check or array list add with a global game obj variable that transitions into another state that sends a event to a prefab.

For some reason, it doesn't send it to a prefab/cube that is created after the player presses space.

I think that is odd when I would like to do this with playmaker 1.7.

A few weeks ago I was experimenting with both unityscript and c# to achieve this, I had problems getting OnTriggerEnter and GetButton functions and voids to work properly.  That's why I wanted to try this.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14400
  • Official Playmaker Support
    • View Profile
Re: Placing game objects on a grid
« Reply #7 on: May 10, 2016, 11:47:55 PM »
Hi,

 Managers can become a pain as your system will grow, so I don't recommand this unless you are experienced and well aware that managers are beasts that call for refactoring more often then if you go with an Object Oriented design approach ( which encapsulate logic and so updating logic is a lot easier and doesn't affect other parts of your system.)

Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14400
  • Official Playmaker Support
    • View Profile
Re: Placing game objects on a grid
« Reply #8 on: May 10, 2016, 11:51:32 PM »
Hi,

 one more thing on this. I know that sometimes these concepts are hard to figure out because of the lack of explanations.

 For me, the best book about this is:

http://www.amazon.com/Object-Technology-Managers-David-Taylor/dp/0201309947

which presents Object Oriented design without any code, just the concepts, it's aimed at managers who need to "shout" at developers sometimes :) ... but if they don't know anything about the concepts, they look silly yet again, so this book help them acquire the necessary vocabulary and concepts.

 I really recommend this read, it's very important, and while you may already be familiar with many concepts explained in this book, having clear examples, good diagrams helps cleaning up your thinking process when you need to apply these concepts.

Bye,

 Jean

coffeeANDsoda

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
Re: Placing game objects on a grid
« Reply #9 on: May 11, 2016, 10:06:03 AM »
Managers can become a pain as your system will grow, so I don't recommand this unless you are experienced and well aware that managers are beasts that call for refactoring more often then if you go with an Object Oriented design approach ( which encapsulate logic and so updating logic is a lot easier and doesn't affect other parts of your system.)

Since this is restricted to 3-5 empty objects that is a issue I have dealing with the manager. Theirs global variables for it but when it has the array list proxy, during runtime the grid point/empty objects to show up, and that's a problem because the prefab cube is suppose to move towards the nearest grid point when set to a global variable object.

I just have a difficult time understanding this because if theirs a manager that has standard array list add, contains and add range objects before it sends a global event to the prefab, shouldn't it move towards that point?


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14400
  • Official Playmaker Support
    • View Profile
Re: Placing game objects on a grid
« Reply #10 on: May 25, 2016, 01:17:42 AM »
Hi,

 I think it's already down to a confusion in the logic of the system, not because it's a manager or because it's using arrays.

-- Can you keep a global variable representing the nearest point?

this would be the first thing to verify, once you have this information, you can send a global event to either the prefab that has to move or to all prefabs which in turn run some logic to decide whether they should be moving or not.

Bye,

 Jean