[solved] same actor used multiple times in scene

xRANDBOx

  • *
  • Posts: 76
So to try to save resources and sanity (keeping track of duplicates) im trying to figure out how to use the same character more than once in a scene. I have attached some pics to help explain. All the logic is on the soldier except for a kill collision on bullet.

To start with, if i spawn or place the soldier in scene results are the same. In the logic i tell the soldier when conditions for firing is true, create a bullet. as you can see the bullet is then placed at the coord of the soldier. The issue is it doesnt know which soldier to place the bullet at since they are all the same character. so it defaults to the last created.

So my question would be. How could i fix it where every soldier creates its own bullet without having to make duplicates of both? Thanks in advance!

« Last Edit: April 15, 2018, 04:05:45 pm by xRANDBOx »

xRANDBOx

  • *
  • Posts: 76
Update:
I got each actor to fire now by switching the bullet re-position directly on bullet create x y. They're still going off the the last created actor facing direction though.

corbanwolf

  • Posts: 86
1. Create attribute of type actor with name "shot bullet" or whatever. This attribute will be exactly that bullet that was shot by this certain soldier.
2. Set "shot bullet" to "last created actor".
3. Stop using "for each actor on screen". Every time the soldier shots the "play pistol" will be played as many times as many bullets are on the screen. Every time a soldier will shoot. Every already existing bullet on the screen will change its opacity, direction and velocity.
4. Kill actor after leaving screen will work better if put directly in testBullet

xRANDBOx

  • *
  • Posts: 76
1. creating attribute didnt resolve the direction of the bullet.
2. shot bullet to last created actor would potentially work if that was last thing being created. i can see instances where the bullet might become a tank flying at the player.
3. i used 'for each' to compile everything on one list for help purpose. perhaps i read this part wrong.
4. again, compiled for display purposes
Thank you for the help.

I think a better way to approach this would be to some how rename the actor upon creation. since i am relying on a spawn system and not placed on screen prior. i havent found a block allowing to rename actors ID/name though. do you know of any?

corbanwolf

  • Posts: 86
1. Instead of velocity you can use push towards x/y. "player cords" - "self cords". Push self this direction.
2. It is the last created actor as long as you set "shot bullet" to be "last created actor" right after creating an actor.
3. Using attribute with last created actor works. Don't be afraid to use it :)
 Everything should work now :D

"the last created actor" is an actor that has been created lastly. It is true that with time "last created actor" will be different actor that it was second ago. That's why we asign this particular actor to an attribute. This way this attribute will refer to this particular actor we wanted no matter whether it is still last created or not

xRANDBOx

  • *
  • Posts: 76
Ok i messed up, for some reason i used Actor Type instead of Actor for attribute. It seems to be working now! thanks for the help corbanwolf!


corbanwolf

  • Posts: 86
One more thing.
While creating bullet. It will be better if you use this: "create test bullet at x of self and y of self". Cuz maybe in future you will make a behaviour that will kill the bullet after coliding with tiles. Once they are created at 0, 0 they will be killed right after being created so now this will save you from future problems :)