Weapon example for Platformer

Get help using Construct 2

Post » Sat Nov 24, 2012 12:40 am

Hey guys, i'm looking for an example on how to pick up weapons and drop them to the floor.
B
10
S
4
G
3
Posts: 46
Reputation: 3,036

Post » Sat Nov 24, 2012 1:16 am

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.


B
50
S
21
G
8
Posts: 844
Reputation: 10,299

Post » Sat Nov 24, 2012 1:47 am

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.
B
10
S
4
G
3
Posts: 46
Reputation: 3,036

Post » Sat Nov 24, 2012 10:14 am

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
Using R238 for all examples
B
60
S
17
G
6
Posts: 363
Reputation: 9,125

Post » Sat Nov 24, 2012 8:01 pm

[QUOTE=emoaeden] 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[/QUOTE]

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.
B
10
S
4
G
3
Posts: 46
Reputation: 3,036

Post » Sun Nov 25, 2012 10:09 pm

Still haven't found a solution on how to pin a weapon to an origin point.

Any help will be appreciated!
B
10
S
4
G
3
Posts: 46
Reputation: 3,036

Post » Sun Nov 25, 2012 11:32 pm

examplecapx

Here is one example i made.I am sure there are better ways but this is what i came up with.
B
22
S
3
G
6
Posts: 1,356
Reputation: 7,141

Post » Sun Nov 25, 2012 11:40 pm

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
B
64
S
8
G
9
Posts: 290
Reputation: 8,590

Post » Sun Nov 25, 2012 11:42 pm

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
B
64
S
8
G
9
Posts: 290
Reputation: 8,590

Post » Mon Nov 26, 2012 12:22 am

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
B
34
S
16
G
16
Posts: 2,222
Reputation: 16,564

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 30 guests