Pin sprites to player and handle collisions

0 favourites
  • 3 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • 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)

    <img src="http://crossbreadtech.com/imageserver/pin-and-collision-events.png" border="0">

    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!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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'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?

    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.

    Also using buildable and buildableother is confusing me, but that might be a personal issue.

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

    <center>

    <img src="https://www.scirra.com/images/articles/assetlist.png" border="0">

    [Image from tutorial example]

    </center>

    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.

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