Problem with changing characters and their collision-masks

0 favourites
  • 15 posts
From the Asset Store
Basic template for drawing game with masks and easy customization
  • Hi,

    I'm working on a game where you can switch between characters with different shapes (square, triangle, circle) and different abilities (speed, jump strength, etc.). They all should have the physics behaviour in order to interact with other sprites.

    What I did: I pinned the sprites to a placeholder and set the z-order (on pressing c = move circle to top of layer, the rest to the bottom). The changing abilities were also set via the event-sheet. Everything fine, but my problem is the changing collision mask. E.G. from square to circle. I tried to connect the character-change with a change to a different animation frame of the placeholder which has the circle collision-mask applied. That doesn't work, the character doesn't change and freezes.

    Is that enough/the right information? Can anybody help me with that?

    Thanks, Held

  • I can think of a lot of reasons for this not working the way you describe it, it would be far easier to solve if you could provide the capx..

    First thing is using the pin behaviour combined with the physics behaviour, physics has joints, why not use those?

    Second thing is disabling the collision for all objects that are not active (if they are all on screen (only z order controls visibility) they could all be interacting)

    Third thing is the placeholder (does it itself have physics behaviour), how have you set it up?

  • Hi,

    I disabled the collision for all except the placeholder.

    I don't have a clue, what joints can do for me in this situation. Can you give me a hint or is the manual my friend?

    Anyway, heres the capx. Hope wetransfer is alright:Thank you.

  • Dropbox Link:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok.. What I don't get..

    Why do the characters have physics behaviour?

    What do you expect to happen that is not happening in your example?

  • Oh, I forgot to turn the "Platzhalter" collision mask back from circle to bounding box. Just made a test.

    The characters have no physics behaviour yet. I deleted that, cause I got even more weird, shaky appearance. Do they need one?

    What doesn't happen, is the changing collision behaviour (not in construct terms) accordingly to the changing of the animation frames and their different collision boxes.

    Hope, I can explain it clearly.

  • Hi Held, it seems to me that your setup is a little more complicated than it needs to be ( if I'm understanding right ). Firstly I would make a family in your project. That way if you apply and behaviours to the family anything placed inside ( i.e your characters ) will all receive that same behaviour. Secondly, is there any reason you are using separate sprites for your characters in the first place? These could just be different animations ( each can have its own unique collision box ) that the game can just switch between? Not sure if any of this helps at all as I am not 100% clear on your direction

    As a side note I see you are using an 'everytick' function to scroll the view. 'everytick' can be a bit of a memory hog, and in this case is redundant as there is a 'scroll too' behaviour that can be added to your player character.

  • Firstly, thanks for your help! I appreciate.

    I plan, that e.g. the square can beat certain some enemies and the circle don't. That's why I thought global variables and different sprites were the way to go. Is there a way to do that, if I only have one sprite with different animations?

    But even more important: I didn't find a way to change the kind of the general collision mask from "bounding bx" to "circle". So, when I change to the circle, on diagonal platforms it shakes like hell. If I choose "circle" from the beginning it's vice versa. The square and triangle are shaking. I thought, with different sprites and a placeholder, I'd avoid that. And that's the point where my problems began. I think, a command to change the general collision-type would be one solution. But thats not possible, right?

    Thanks for the every tick-hint.

  • you do know you can edit the collision polygon inside the image editor, right?

    So removed all the physics and removed the platform behaviour from all objects except the placeholder..

    And everything is a lot smoother..

  • Held You can make a condition that checks what animation/frame the object is on, so for example: On collision with "Enemy1", if playing animation "Circle" Destroy "Enemy1". That way your game will know what to do if it is playing a different animation.

    But there is nothing wrong with using different sprites either, its just a little harder to manage and means you have more code. You could also use Arrays for this but if your new to construct 2 I wouldn't get into them just yet ^_^!

    In connection with your collision mesh, if you double click a sprite there is an icon at the bottom of the Left hand side panel in the edit image box that is called set collision polygons, you can set this to be different for each animation or frame ( you can al,so right click to apply the same collision mesh to the entire animation or even ALL animations )

  • little stain: Thanks, it really runs smoother. But, as I wrote, I wanted physics in order to interact with other objects.

    Yes, I do know about the image editor and the ability to set different collision polygons. But thats part of the problem. As I wrote before: "Everything fine, but my problem is the changing collision mask. E.G. from square to circle. I tried to connect the character-change with a change to a different animation frame of the placeholder which has the circle collision-mask applied. That doesn't work, the character doesn't change and freezes."

    The change from square to circle (with the change of the collision masks) results in the game freezes.

    Furthermore: If my characters don't have physics on, they remain straight and don't take the angle of e.g. a ramp they're stepping on. As in your project-file. Check by yourself.

    RandomOutput: Thanks for the "if playing..."-tip.

  • Why would they need physics to interact?

    And if you are going to use physics for that why not completely make your game in physics, because a well known issue is that physics doesn't interact well with other behaviours?

    The "problem" of the characters staying straight can be solved with programming, no need for physics there..

    If you are going to change collisionmasks one thing to make sure is that when the new collisionmask is applied it doesn't automatically overlap another, this can also be done with some programming..

  • Hi,

    don't know, what it means to do it completely in physics. Can you explain?

    But I need physics for upsetting objects (realisticly), right?

    How can I avoid overlapping by code?

    Thanks again.

  • Held, I'm guessing the problem comes with switching a smaller collision ( Circle ) with a bigger one ( Square ) Causing the collision mesh to get stuck in the solids. Have you tried offsetting the position of the Square character on change so that when you change it lifts it ever so slightly above the ground? You could also, so it does not get stuck if you change by a wall, get construct to check if there are any objects to the left or right of your character ( based of a certain distance ) that would either prevent or allow a switch if there was a risk of the collision mesh getting stuck. If you can provide the .cpx I might be able to give it a look over. If you worried about game ideas just strip everything that is not needed out of it.

  • Sounds like that might be the problem. For practice, I will try to work it out. If I stuck, I'll provide the capx and be glad, if you could take a look. I will give a report.


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