• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How to have your character pick up weapons?

T

TGSP

Guest
So I'm making a game where I want the character to be able to pick up guns and other weapons. How would I achieve this exactly? How do I attach the weapon sprite to the character sprite by walking near it and pressing a certain key?
 
T

Ting_Thing

Guest
Well, you press the certain key, remove the item, play a sound effect, etc. You could then have a variable for your character... for instance, obj_character.has_gun = true.

How do I attach the weapon sprite to the character sprite
There are several ways. I think the easiest is to simply make a separate sprite(s) for your character when holding the weapon. However, if you have a lot of different-looking weapons and a lot of sprites for your character that would need to adjust, it's probably better to draw the weapon separately. You could create a special sprite of each weapon when it is being held by the character. Make a copy of your character sprite, draw the weapon on the sprite, and then erase the character part. Then in your character Draw event, you would have something like this:

Code:
draw_self()
if has_gun = true
draw_sprite(sprite_gun_held,0,x,y)
I hope that helps!
 
A

AlphaRedDragon

Guest
You cold also have a separate weapon object that just acts differentially based on what weapon you have picked up. and just have the object always set its x and y to the players
 

Fabseven

Member
You could also create an obj_parent_pickable witch is the father of your other pickable objects and in your player objects in the collision évent with obj_parent_pickable
Code:
Switch(other.type)
{
 Case 0: has_gun = true; break;
 Case 1:has_machinegun = true;break;
 Case 100: has_grenade = true; has_grenade_number+= 1; break;
}
Other.destroy = true //in the step évent of your obj_parent_pickable check if destroy == true to destroy obj
Where type = type of weapon
Good tips too : in the step évent of obj_parent_pickable : when player range < 100 move to player.

Something like that....
 
T

TGSP

Guest
Thank you for all your replies, I've decided to go with the simplest of options and make it so if the character touched the gun, the gun will have the x and y coordinate of the character. The only problem I'm having is that the gun doesn't really stick to the character if that makes any sense. It follows the character and kinda lags behind it. Not really staying in one place on the character. So is there a way to make the gun completely stick to the character in one place and not move around or lag behind?
 
Top