Weapons family to characters family

0 favourites
  • 12 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Hi all,

    I am no coder, and have been trying to wrap my head around family. I read and downloaded the tutorial on picking instance on families, but hitting a brick wall understanding.

    Basically I created 2 weapons in weapons family, 2 players in players family, right now when one of them overlaps any weapon object. They both equip both weapons.

    Would anyone be able to kindly show me how this could be done?

    I have attached a capx:

    drive.google.com/file/d/1tnbEPIj7ty8sSOp0-LElN2N3h8Dqd_cB/view

    Thank you!

  • Here's what's happening

    On Player Collision with Weapon

    This is 'picking' the player and the weapon involved in the collision. Any future actions within this block will be applied to THIS player and THIS weapon

    Destroy Weapon

    Here, you destroy the weapon that was picked. Now the weapon is no longer picked, since it no longer exists

    Player spawn Weapon

    Since no Weapon is picked, the game just spawns both types of Weapons at random, since it doesn't know what you want

  • kidswithcrowns

    Thank you. That makes sense, but I still don't know what the next steps are to allow P1 to take gun when they are overlapped.

    (these are probably all wrong approaches) - I tried taking out the destroy, but it would just spawn the gun everytick. I tried set weapon position Player.ImagePointX(0), Player.ImagePointY(0), but it would jump between players randomly.

    What do I need to do next, would you be able to give me an example?

    Thanks in advance!

  • kidswithcrowns

    Thank you. That makes sense, but I still don't know what the next steps are to allow P1 to take gun when they are overlapped.

    (these are probably all wrong approaches) - I tried taking out the destroy, but it would just spawn the gun everytick. I tried set weapon position Player.ImagePointX(0), Player.ImagePointY(0), but it would jump between players randomly.

    What do I need to do next, would you be able to give me an example?

    Thanks in advance!

    Sure!

    You have the right idea with taking the weapon. Any of your methods would work. The part that is making it act weird is the condition "Player on collision with Weapon". Every time you give the weapon to the player, it's re-colliding with the player and retriggering the collision

    There are many ways to solve this, and they all involve making it so the "On collision" trigger only fires if the weapon is being picked up

    one way is to give the weapon family a boolean called "equipped"

    then add a condition to the collision event that checks if the weapon is NOT already "equipped" (you can right click an event and click invert)

    if it's not "equipped", go ahead and spawn a weapon on the player and immediately set the weapon's "equipped" bool to true so it doesn't trigger the collision event again

    ufile.io/84fuklb7

  • minipill

    EDIT: I didn't refresh the screen so I didn't see the other replies while I was playing around...

    what is happening is not quite what you think.

    when a player collides with a weapon, you destroy the weapon and spawn a new one on that player.

    however, when you spawn an object from a family, you get a random member of that family... so you don't know which weapon you will get.

    AND spawning a weapon on the player makes the player collide with that weapon, which then causes that weapon to be destroyed and another random one created.

    the reason why it looks like both players are getting equipped is that your collision boxes on the weapons are a lot bigger than the actual image, so when you are moving the players, they are both colliding with a weapon, and then both running the endless loop of destroying and creating a new random weapon.

    So, what you probably want to do is add an instance variable to the weapon family called "Equipped" and set it to false. Then when a player collides, pin it to the player and set it to equipped so the other player wont pick it up if they cross paths...

    https://www.rieperts.com/games/forum/weapon_test.c3p

  • kidswithcrowns & AllanR

    OMG Thank you so much!! You guys made my day, this has been bothering me for days.

    Glad the construct community is so good.

    :)

  • AllanR

    Hey all! Thanks for all the help previously, I have been playing around more and needed to pin a sprite over the collision player box where the weapon will be pinned to the sprite's image point. I think it has to do with UID? (not even sure if this is correct assumption). I cannot figure out how to implement it into this build.

    I tried it below but the weapons are either pinning to an invisible point far away from the sprite, or pinning to the wrong character. Any help would be amazing! Thank you.

    Attached what I tried:

    ufile.io/sv6mw0zr

  • minipill

    event 2 checks for a collision between "weapons" and "player"

    but then in sub event 6 you are moving the weapon and pinning it to "Sprites" family. But there is no Sprites family picked, so it is not using the one you want.

    in event 6 move the weapon and pin it to the player family instance (which is picked because of the collision triggered in event 2).

    You are on the right track... it is a good idea to pin images on top of a hidden player object - that allows you to customize the character, change armour, weapons, etc. But you should always pin everything to the base player object, otherwise there is a slight lag when things are moving which doesn't look good.

    (so, you don't want to pin a body to the player, then pin an arm to the body and then pin a weapon to the arm...) pin everything to the player, and they will all move together the way you want. But that can cause issues with being able to animate things the way you want. If you need complex moving of multiple parts, then you should use something like Spriter.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • AllanR

    Nice! Thanks Allan. Since I really want to have the weapon follow the "hand" imagepoint in the animation, I made a modification and put WeaponUID variable in Sprites instead of player, and made Sprites collision enabled (eventually I can make the collision box much smaller). Now I can check for collision between sprite and weapons and it follows. (not sure if this would have implications in the future).

    But When I set [line 6] Weapons position to Sprite (image point 1), it only follows the point on the first frame of the animation. How can it follow throughout the animation? (frame 2-4) so its following its hands?

    Did a bit of research someone pointed to the direction of rexrainbow's pintoimagepoint plugin. But I don't think it works for Construct 3?

    Attached modified capx

    ufile.io/lafspkkv

    Any help would be hugely appreciated

    Thanks again.

  • if you want the weapon to follow the hand, then every tick move it to the image point (without using pin - which will lock it at the one location).

    so, you need to pick players holding a weapon, and then do a for each loop so you can pick the correct weapon, and move it to image point "Hand"

    https://www.rieperts.com/games/forum/weapon_test2.c3p

    EDIT: I didn't remove the Unpin actions from earlier events, but since the weapon is not pinned, that wont cause trouble, but obviously those could be removed...

  • Thanks heaps AllanR this is amazing!

    Currently the space bar releases both weapons simultaneously, is there a way to allow the space bar to release the weapon on one player only, and another key to release the weapon on another player? This one seems like a difficult one to do

    Thanks

  • the easiest way to do that was to create a global variable to keep track of which player is the active player...

    then I made space bar just drop the active player's weapon.

    I also added press Enter to switch between player 1 and 2.

    to keep it simple to know which sprite body goes with which player, I also added an instance variable to player that holds the UID of the sprite body.

    https://www.rieperts.com/games/forum/weapon_test3.c3p

    there are plenty of other ways it could have been done... Press 1 to drop player1, press 2 to drop player2

    or press g to drop whoever is holding the gun, etc...

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