Align Sprites to Player then Pin

Get help using Construct 2

Post » Sun Dec 15, 2013 9:42 am

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.

.capx

Any suggestion for a better technique for avoiding the overlap would be greatly appreciated.
B
8
S
1
Posts: 13
Reputation: 455

Post » Sun Dec 15, 2013 9:52 am

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.
LittleStain2013-12-15 09:53:29
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Dec 15, 2013 11:42 am

Thanks for the quick reply! 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.
B
8
S
1
Posts: 13
Reputation: 455

Post » Sun Dec 15, 2013 12:14 pm

[QUOTE=LittleStain]

player on collision with part:
-slot destroy
-part destroy
-player spawn part at imagepoint
-part pin to player

[/QUOTE]

It WORKED!!! 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
B
8
S
1
Posts: 13
Reputation: 455


Return to How do I....?

Who is online

Users browsing this forum: htmlgames, Matei511 and 64 guests