How do I pin multiple objects to multiple different image points?

0 favourites
  • 7 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • So in my game, you shoot arrows at enemies and I want the arrows to stay pinned inside them. I've been trying to make a sort of custom pinning function so I can pin the arrows to certain enemies' image points, but it hasn't been working.

    My method is whenever an arrow collides with an enemy, it stores the UID inside of an instance variable and then having an event "pin" the arrow and enemy's image point after. This works if there is only one enemy pinned, but it multiples I've been finding that all of the arrows stick to the first enemy that got pinned. I suspect it's because the action is only picking the first enemy with a UID that matches the arrow's instance variable.

    So is there any way that I could set the position to an object's image point based on the UID as an action? I don't know any javascript, but maybe it would be possible using that?

    Tagged:

  • Why do you need UIDs here? This should be enough:

    Arrow on collision with Enemy -> Arrow pin to Enemy

    .

    In case later you need to destroy the Enemy with all arrows in it, you can do this:

    Enemy on destroyed
    System pick Arrow by evaluating Arrow.Pin.PinnedUID=Enemy.UID 
    	-> Arrow destroy
    
  • Why do you need UIDs here? This should be enough:

    Arrow on collision with Enemy -> Arrow pin to Enemy.

    I want to pin the arrows to an image point, so I'm using the UIDs to make a custom pinning action that runs every tick. The UIDs are for the instance variables on the arrows, so I know what enemy they're pinned to.

  • Your explanation is a bit confusing. So you are not using Pin behavior?

    In this case:

    Arrow on collision with Enemy
    Arrow compare variable EnemyUID=0
    	-> Arrow set instance variable EnemyUID to Enemy.UID
    
    
    Every tick
     Arrow compare variable EnemyUID>0
     System For each Arrow
    	Enemy pick by unique ID Arrow.EnemyUID
    		-> Arrow Set position to Enemy.ImagePointX(1), Enemy.ImagePointY(1) 
    
  • That's what I did, sorry if my explanation was confusing. The problem with that code is that when you "pin" multiple enemies, every arrow after the first one gets "pinned" to the first enemy hit.

    So let's say there are 2 enemies, enemy A and enemy B. If I shot enemy A and then shot enemy B, the first arrow would pin correctly to A, but every arrow after that, even the ones shot at B, would still pin to A.

  • With my code this should not happen. Notice I used "System For Each Arrow", it's important here.

    If this doesn't help, you'll need to post a screenshot of your events or the project file.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It works! I think I tried the For Each before, but I guess I didn't format it right. Thank you so much for the help, I'll leave a screenshot of the event here in case anyone needs it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)