Pin sprites to player and handle collisions

Get help using Construct 2

Post » Mon Dec 16, 2013 12:48 pm

I'm designing a game (my first in Construct 2!) for Ludum Dare 28 where the central element is that the player can add parts they salvage onto their vehicle. I've tried two different approaches now, and the current one is more clean and takes advantage of families, but it still doesn't work completely.

The intended behavior is:
1) When player collides with armor, mount (pin) the armor to the player (directly under it).
2) When armor collides with other Armor, snap/align the other armor and pin to existing armor.
3) [not implemented] When armor collides with a cannon, pin the cannon directly on top of the armor. (Same for anything else in the Mountable family)



Right now #1 works. For some reason, the collision between two armors only works for the first layer (adjacent to the player, and armor it's mounted to.) Even then it inconsistently snaps to the wrong (not nearest) image point. Also the first collision seems to be ignored, but on a second pass it picks up the block.

I'm pretty stumped and have been staring at this literally all day, read tutorials, the manual, googled, etc. Learned a fair amount, but I still can't figure out what the problem is here.

pin-and-collision.capx

The green squares are spawned on top of any non-zero image points of the armor so that I can use pick nearest. They store the image point they were spawned on so that I can then move the new part to that location and pin it to the player.

The Buildable and BuildableOther families are mainly to facilitate performing specific actions on the two armor sprites when they collide.

Another element of the game is that you have to fight yourself (Pressing R should build a copy of you) although I'm pretty sure that's broken after I ripped out my first attempt. To do this, I was recording the type and X/Y distance from the Player for every part added in 3 arrays, type, X, and Y.

The problem with this is that if the player was turned sideways, the coords could be off, so reconstructing the clone didn't work unless I locked down the player's freedom to rotate. I had considered using relative polar coordinates instead, capturing angle relative to the player, distance, and type. But if there is a better way to do this I'd love to hear it.

Here's the live version if you want to see what I'm talking about.

I'm super impressed with how helpful this community is, so thanks in advance!
B
8
S
2
Posts: 13
Reputation: 605

Post » Mon Dec 16, 2013 1:11 pm

I'm thinking you are overcomplicating things a bit.

Couldn't you just have the direction the object is moving on collision determin the imagepoint to connect to?

Also using buildable and buildableother is confusing me, but that might be a personal issue.
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 » Mon Dec 16, 2013 9:28 pm

[QUOTE=LittleStain] I'm thinking you are overcomplicating things a bit.

Couldn't you just have the direction the object is moving on collision determin the imagepoint to connect to? [/QUOTE]

I'll give that a shot and see if it works any better. The idea was to be able to expand to pieces that aren't a single block and might have more than one slot on each side. Like Tetris pieces or something. Your suggestion may at least get my game playable for the game jam though.


[QUOTE=LittleStain] Also using buildable and buildableother is confusing me, but that might be a personal issue. [/QUOTE]

As for the family usage, I was trying to follow the pattern discussed in this tutorial: Understanding picking with respect to families


[Image from tutorial example]

But instead of Buildable_1 and Buildable_2 my families are named Buildable and BuildableOther, since Collision in some other engines allows you to refer to the two objects involved as "self" and "other". I've really had trouble wrapping my mind around C2's very indirect way of referring to a specific instance. I think the best description I found suggested to think of it like writing SQL instead of OO code like Java. This families approach seemed to be the simplest I've run across that didn't involve pinning ghost copies to everything which seemed like more of a hack.
B
8
S
2
Posts: 13
Reputation: 605


Return to How do I....?

Who is online

Users browsing this forum: Artcadev and 40 guests