playMaker

Author Topic: Picking an object/prefab  (Read 2169 times)

Ran_TH

  • Playmaker Newbie
  • *
  • Posts: 5
Picking an object/prefab
« on: November 22, 2013, 01:19:42 AM »
Hi, sorry if this is rather a simple question but I still have to hang around with PM more...

So basically there's a player and 5 balls on a stage. Those balls are duplicate from a prefab.
I want my player to pick a ball by pressing "space" key, bring the ball with the player and dropped it with the same key. This one sounds easy, but I'm still confused on how to make its flowchart.

If anyone can be able to give some hints that might be appreciated :)

bkups2003

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Picking an object/prefab
« Reply #1 on: November 22, 2013, 04:32:31 AM »
Just some quick ideas off the top of my head:

When you press SPACE:

- Use Find Next Child to loop through the ball prefabs on the stage(since there are only 5), get distance, compare with a value for the range you can pick up in (eg. 1 meter), if it's within that range, pick up (set parent to character)! That's the most basic and quickest way i can think of. You can also do a quick Has Child on the character to check if you are already carrying something and if yes, set the child of that back to wherever it was and bypass the whole distance loop. Throw in a check for rotation too so you know it's in front of you.

Drawbacks: I hear distance checks are a little heavy. The loop will grab the first one that it checks thats in range (even if the next one in the loop is closer) and grab that.

-Use Colliders on your character and the balls and on SPACE, check if there are any balls colliding with your character. Add all of them to an array. Check what is closest to being in front of you. You can go with what i said above and also parent to the character, or do it your way etc. etc.

Colliders are probably the best way to go. There's always quite a few different approaches. And there is alot you need to consider. When picking up the ball, you don't want it rolling around anymore. So you have to enable and disable that together with picking up and dropping. You can use an action to move the ball directly in front of your character when it has picked one up, instead of having it always at the angle it was picked up on. And so on...

Ran_TH

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Picking an object/prefab
« Reply #2 on: November 22, 2013, 07:29:14 AM »
Thanks for your answer :D Yes the collider approach is the one that I'm using and I think the simplest one. I just need a FSM that picks up the ball that it colliding into and set it as parent. Problem is I can't think of method to detect which ball is colliding..

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Picking an object/prefab
« Reply #3 on: November 28, 2013, 05:28:18 AM »
Hi,

 when colliding, your first action should be "get Collision info" or "get trigger info", and in there you can save the reference of the ball that collided, and then you can use this reference to parent things together.

bye,

 Jean