So I’m trying to figure out how do I get my player hold a different weapon when it collides with an object
currently my player already has a weapon attached to it from the get go but I want the weapon to get replaced by a new one when it collides with certain power ups but I don’t know commands how to do so.
First part, this is the point where the gun is located at on the player
Second part is when the gun rotates along with the player
Hi, what you basically need is just an event that has the condition: “player collides with power up” and the actions: “delete gun” + (for example) “create shotgun” at player.PointX(“Gun”), player.PointY(“Gun”).
If you have many weapons and don’t want to make a “change position”-event for all of them individually, you could make a weapon group and use that instead.
Ok so I tried this out, and here are the results.
The yellow box represents the power up to be collided with and the blue box represents the new weapon I’m supposed to pick up but when I collided with the yellow box the blue box doesn’t attach itself to the player.
Because the results are still the same, it still doesn’t attach itself to the player
So Instead of the player colliding with the yellow box I instead have it collide with the blue box instead so that fixed the problem. but I still have something in mind which is having the weapons on the players hand rotate, I already have a condition for the default gun to rotate along with the player when its facing different directions, my question is can I just make the weapons rotate based on what the player is holding or do I have to make a condition for every weapon?
You have changed the typo with PointY but your event is different (now it is ‘change the position’ instead of ‘create’). My suggestion was to create the new weapon-sprite at the GunPoint in the collision-event and to move the new weapon, like the gun, with the ‘change the position’-action without condition in another block - you’ve got it already, there was just the typo.
If you just want to have one event for rotating (and maybe just one for changing the position) for all your weapons, you can make a group (e.g. ‘weapons’) and apply all the weapon sprites to that. In your events you can use the weapon group instead of each single sprite-object and the events will work for all the members of this group.
I have another question, what if I want to replace the gun whatever is in the “GunPoint”? because I have plans on adding multiple weapons.
How would I tell the game to delete whatever the player is holding and replace it?
Like for example, player is currently holding gun A and it collides with a gun create
I want the game to delete whatever it is holding and replaced with a new one.
The thread didn’t help on anything there as the thread starter’s problem was holding 2 weapons while I just want mine to delete whatever the player is holding and replaced with whatever weapon it collides with
Ok so I’ve tried this method and it works just fine thank you!
Now I’m just curious if instead of deleting the weapons one by one in the events, is there a better way of just getting rid of them in 1 action? because one way I’ve tried is this
That is pretty clever
I did not think of that
And i abuse groups in my projects left and right
If i understand correctly you are deleting each object from gun group so no matter which gun player is holding it will get deleted?
If so then this is kinda best way
I mean there are others but they would involve checking variables
Or making slot object and deleting anything from slot object
But your method is pretty much most simple i could think of
Again damn clever idea
You really should be proud of yourself