Align Sprites to Player then Pin

0 favourites
  • 4 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • I'm using Construct 2 for the first time for the Ludum Dare 28 competition. I looked through the FAQ and searched the forum but I didn't find something that looked similar, although I may just not have the experience to recognize my solution yet.

    In my game, the player can collect parts that will snap to open slots. I did this by creating objects at 4 image points outside the player, then checking for collision between parts and those "slot" objects.

    On collision I set the part position to match the slot (they're the same size) and then immediately pin the part to the player and destroy the slot. However, I end up with weird offset with each part. For example, instead of being exactly 16 pixels away on the X axis from the player, I see values like 13.9023999. It's different every time, regardless of the speed the player is traveling when the collision occurs.

    It mainly just looked bad until I added the solid behavior to the parts and player (which I think I need to keep the enemy from passing through), but now, understandably it drives the player off the screen trying to stop overlapping the sprite pinned to it.


    Any suggestion for a better technique for avoiding the overlap would be greatly appreciated.

  • The capx has a third party plugin "chrome console" that I don't use, so I can't open it.

    Maybe it would help if you set it up this way (I don't know if the slots are there for any other reason than handling the position)

    player on collision with part:

    • slot destroy
    • part destroy
    • player spawn part at imagepoint
    • part pin to player

    I think it would be easier.

  • Thanks for the quick reply! <img src="smileys/smiley4.gif" border="0" align="middle" /> I'll give that a shot. The slots were just there to facilitate the alignment and detecting a part.

    Sorry about the bad .capx. I deleted all the usage of the chrome logging thinking that would remove the conflicts. If your suggestion doesn't resolve the issue, I'll figure out how to downgrade so I can post the file.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • player on collision with part:

    -slot destroy

    -part destroy

    -player spawn part at imagepoint

    -part pin to player

    It WORKED!!! <img src="smileys/smiley32.gif" border="0" align="middle" /> Thank you, I've been fighting with that for half the day. When I started I didn't realize there was a "Spawn at image point" action (since I was looking for something with "create"). The only modification it required was storing the image point index on the Slot object and then referencing that to spawn the part just before destroying it.

    I also tested enabling the solid behavior of the parts again and that works fine. I do have the collision detection boxes set 2-3 px smaller than than my 16x16 Part size though.

    So, for anyone's future reference:

    On Player Create:

    • Loop over image points
    • Spawn "Slot" sprite for collision detection at each one
    • Store corresponding image point on the Slot

    On Slot collision with Part:

    • Destroy Part
    • Spawn Part at image point (use point stored in Slot)
    • Destroy Slot
    • Pin Part to Player
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)