Weapon example for Platformer

0 favourites
  • 10 posts
From the Asset Store
Unlock platyers earning coins, and save it with Localstorage
  • Hey guys, i'm looking for an example on how to pick up weapons and drop them to the floor.

  • I don't have an example file right now, but here's the basics.

    There's a few different ways to do it depending on your game, so here one way.

    If you want your character to automatically pick up the item when they walk over it then you simply need to use the event "On collision with other object" and pick the player object as its target.

    If you want the player to also have to press a button to pick up the item, then add the keyboard object to your layout, and right click the "on collision with player" event you just created and choose "add another condition" and pick "keyboard" -> on key pressed ->"B"

    So now the action associated with overlapping the weapon on the ground will require the "B" button to also be pressed in order to execute the action.

    Now for the action. Depending on how you want to make your game, you could do a few different things.

    1- the player has its weapon's built into its animation sprites already, and you simply need to switch to a different frame (eg one with him holding his gun) in which case you would use the "set animation" action

    2- The weapon item "pins" itself to the player and follows him wherever he goes. In which case, you need to add the "pin" behaviour to the weapon, and use the "pin to object" action.

    3- Lets say the player always has the same gun, but just fires different bullets depending on which item his picked up. In this case, you would create a instance variable for your player called "currentGun" or something. And for your weapon pickup action you would use the "set value" action to change the player's variable to 1 or 2 or 3 or whatever. Then you could create an event on the player that checks which value that instance variable is, and switch the animation or damage or graphics of the gun to whatever you want.

  • Thanks for the reply.

    I have the main character pick up a weapon by pressing down. I tried the Pin behavior and it works fine except that when i pick up a weapon, it pins to the characters feet instead of his hand.

  • Yo just need to make a second origin point by double clicking on the character sprite, then go to image point and make one where you want the gun to be. Then tell the game to pin to that origin point

  • Yo just need to make a second origin point by double clicking on the character sprite, then go to image point and make one where you want the gun to be. Then tell the game to pin to that origin point

    Yes, i have an origin point called "weaponpoint" but i dont know how to set the Pin to that origin point. It doesn't give me an option to do that.

    I can only pin it to an object but not an origin point.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Still haven't found a solution on how to pin a weapon to an origin point.

    Any help will be appreciated!

  • examplecapx

    Here is one example i made.I am sure there are better ways but this is what i came up with.

  • instead of pinning the gun right away, when they pickup conditions are met, first use the "Set Position To Another Object" action, that'll give you the chance to select the player sprite and enter the image point you made, then right underneath that action, make the Pinning action happen

  • Pinning makes the pinned object stay connected to the first based on relative position when first pinned, so if you move the item where you want it before you Pin it, it'll work perfectly

  • You guys aren't seeing the solution even if it is on your noses !

    Why complicate your life ! Just make an animation with the weapon and without the weapon ... You could switch from animation to animation with an event !

    If you have a lot of animations just set the origin to the place you want the weapon to be , then add a boolean ( IsWeaponEquiped )

    Add those events :

    On "b" pressed :

    -If IsWeaponEquiped true :

    -- Set IsWeaponEquiped false

    -If IsWeaponEquiped False :

    -- Set IsWeaponEquiped true

    And

    If IsWeaponEquiped true :

    -- Set Weapon position to ( Player.X , Player.Y )

    No need for that buggy pin behavior !

    Cheers

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