playMaker

Author Topic: Help using PoolManager for bullets  (Read 1955 times)

Lostcity

  • Playmaker Newbie
  • *
  • Posts: 31
    • View Profile
Help using PoolManager for bullets
« on: June 10, 2014, 01:36:49 PM »
I recently got PoolManager 5 and I'm using it for my enemies and bullets. With my enemies, I had an issue where they would spawn in an already dead state (therefore you couldn't kill them). That was solved by adding a new Start state to my enemies health that reset their health float value. However, I can't figure out how to solve an issue with my bullets. Here is what's happening:

1. The PoolManager preloads 5 bullets from my bullet prefab.

2. The original 5 bullets work exactly as they should. They shoot at the correct impulse value and the correct direction.

3. After the original 5 bullets are used, PoolManger stars to recycle from the old bullets. Here is where the problem comes in.

4. Sense PoolManger recycles the old bullets, it also keeps their most recent rotation and position values. This means that the bullets shoot off in random directions.

I searched online and it seems that other have had similar issues when pooling rigid-bodies. One of the suggestions was to set the object to kinematic when de-spawn is called and turn it back off when Spawn is called. It didn't work. I also tried using a similar method as it did with my enemies. So I tired setting the rotation values at the Start state. That didn't work either.

Again the issue is that the PoolManger is keeping the most recent transform values of the destroyed bullet. Has anyone else had this problem with projectiles? What is the best way to retain the value of the original prefab when recycling objects? 

1982

  • Junior Playmaker
  • **
  • Posts: 71
    • View Profile
Re: Help using PoolManager for bullets
« Reply #1 on: June 10, 2014, 01:45:20 PM »
Reset Bullet's transforms right before it is shot again.

Lostcity

  • Playmaker Newbie
  • *
  • Posts: 31
    • View Profile
Re: Help using PoolManager for bullets
« Reply #2 on: June 11, 2014, 01:36:23 AM »
I've tried that and it didn't work. Here are all the things I've tried so far with my bullet:

1. Tried calling a Set Float Value (for impulse speed), set position and set rotation as the Start state. Didn't work.

2. Tried setting the rotation and position at the last State (same state where the De-Spawn action is called). Didn't work.

3. Tried setting the bullet to kinematic on Despawn and turning off kinematic on Start (this was suggested on the PoolManager forums for rigid bodies). Didn't work.

It's the craziest thing. I'm running out of ideas. PoolManager allows me to preload a set amount of bullets and the pre loaded ones work exactly as they should (though the impulse speed seems a little slower than usual). However, once I run out of the original preloaded bullets, the remaining bullets end up flying off in random directions when I fire them.

I thought the rotation value was the issue but I guess not. I can't think of what would cause my recycled bullets to behave so odd.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14564
  • Official Playmaker Support
    • View Profile
Re: Help using PoolManager for bullets
« Reply #3 on: June 11, 2014, 04:54:43 AM »
Hi,

 I would ask on PoolManager Forum to get an idea of how they tackle that kind of systems, and get back to me, I'll see if this is supported, else I all create what's needed to allow for this.

 But, reseting should/must work here. Basically, a prefab in a pool should never rely on its current value, and instead enforce them everytime it's instantiated.

Bye,

 Jean

1982

  • Junior Playmaker
  • **
  • Posts: 71
    • View Profile
Re: Help using PoolManager for bullets
« Reply #4 on: June 12, 2014, 03:40:08 AM »
Btw, is there any chance that the bullet has it's previous velocity when it is re-spawned?

(seems like you already tried set its kinematic on/off, that should solve it...)
« Last Edit: June 12, 2014, 03:42:03 AM by 1982 »

Justin

  • Junior Playmaker
  • **
  • Posts: 58
    • View Profile
Re: Help using PoolManager for bullets
« Reply #5 on: February 23, 2016, 01:34:56 AM »
I know this is old, but I wanted to post a solution I used anyway just in case someone else has the same problem.  I was able to fix a similar problem I was having by removing the action to add force on the bullet's FSM, and instead apply force to the bullet in the FSM state that spawned it via variables. I may be wrong but I think when poolmanager respawns an object for the second time it confuses the world/self space on some of the PM actions. Not sure how you had your FSMs setup but if this is still an issue for you a year and half after the fact... maybe this will help  ;) 

krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 990
    • View Profile
    • Fat Pug Studio
Re: Help using PoolManager for bullets
« Reply #6 on: February 23, 2016, 02:40:28 AM »
Have you tried setting the velocity directly instead of using impulse speed? I've heard that it can mess things up in some pools.