• 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!

GameMaker [HELP] How to make an action RPG shield

A

ArKeid0s

Guest
Hello I am a beginner on GMS and I'm making an action RPG game in the style of children of morta or eitr. I would like to create a shield for my player and I would like to make it possible to block enemies attacks. My big problem is that I have no idea of how to do that ^^
If there is already an answer of my problem please link it (I have already seen tutorials for top down shield all around the player for the shump but it is not what I am looking for) if not please help me ! :D
 

The-any-Key

Member
Step 1 create a sprite of a shield.
Step 2 make you player equip it.
Step 3 create a shield block button.
Step 4 when enemy hit you check if player block then don't deal damage.
 
W

Woochi

Guest
A directional shield? If so, for that you need the characters facing direction, as well as the point_direction() towards the attack (from character's as reference): Within a certain angle range of players facing direction, block the attack. If you want a shield in the sense of a barrier, see post above
 
A

ArKeid0s

Guest
No I would like a directional shield but I'm totally new to GMS so could you help me a little bit more please. Thanks
 

Yal

🐧 *penguin noises*
GMC Elder
@The-any-Key: you're not particularly helpful, point 4 in your bulleted list basically was a vague rephrasal of the original question...

@ArKeid0s:
One idea: just draw a shield on the player. When you hit an enemy attack, do something like this to see if the attack hit you in the shield or somewhere else:
Code:
if(abs(angle_difference(other.direction + 180,player_facing_direction)) < shield_angle_tolerance){
  //attack was blocked, play a "ting" sound or whatever
}
else{
  //Attack wasn't blocked, take damage
}
player_facing_direction would be the direction the player is facing, there's a bunch of ways you could compute this - for instance, if you use an animation system based on separate sprites for up/down/left/right, you could check what sprite you're currently using and set this direction to 0, 90, 180 or 270. (meaning right, up, left and down, respectively). other.direction would refer to the direction of the attack; projectiles could use this verbatim, but melee attacks probably won't be moving around a lot so you could compute the direction of those in some other way (e.g. set it when the attack hitbox is created based on the direction the enemy attacking is facing).

And shield_angle_tolerance is how lenient you'll be with diagonal blocking, if your game is gonna just have 4 directions the player can face, something between 45 and 89 should be enough here.
 
A

ArKeid0s

Guest
I would like to do 8 directions it looks better for an action rpg. Thanks a lot for your messages I will think of that and ask more question later ^^
 

chefdez

Member
The-any-key is right, speaking from the perspective of someone learning code with GML for about 5-6 months now, it is particularly difficult to come up with an 8 directional shield as a beginner. I still have TONS of trouble doing even the basic things - without any coding experience or schooling, it is a very long learning process.

Instead of stretching your goal to 8 directional movement with a shield that prevents you from taking damage, (which is a lot of work because you still have to create the arrays, the health variables, the collisions with player to enemy bullets and vice versa.) you should begin with something very simple like creating a player object that can spawn a shield if a certain button is pressed.

So from a beginners perspective this is how I would do it:
Create my player object, bullet object, shield object, and enemy object
I would have my enemy constantly fire at the player object
The player would have to press a certain key or mouse button to create the shield (using the instance_create function)
When the bullet collides with the SHIELD, then destroy the bullet


Good luck! Remember to keep your goals realistic and keep learning bud! Take care
 
A

ArKeid0s

Guest
Ok thanks but my player will always have his shield on so when I'll press the shield button, I will play a little animation in guard position. But yeah your are right I have to stay realistic.
Thanks a lot if you have other advices to give please do I want to learn ^^
 
W

Woochi

Guest
Ok thanks but my player will always have his shield on so when I'll press the shield button, I will play a little animation in guard position. But yeah your are right I have to stay realistic.
Thanks a lot if you have other advices to give please do I want to learn ^^
Just try to break the problem down into smaller steps, like:

1. what do you need? -- a directional shield.

2. how does a directional shield behave? -- it intercepts the process of damaging.

3. Under what conditions?
--Only when the shield is pointed toward source of damage. (A shield does not protect the back, as we know.)

So far, this had nothing to do with programming, it was just about general shield mechanics. However, if you had kept this in mind beforehand, you would have known that the first reply to your post couldnt possibly provide such shield, as direction was not taken into account at all (not to discredit help in any way, this is just for the sake of feedback on your own thought process). Instead, you were surprised that is was so easy.

Now to continue, geometry is added:

4. Now, point 2 is straightforward to implement, but how do we know when shield points toward the source of damage (3)?
-- pointing towards something implies a pointer, its angle and a something to point to.

And game maker:

5. How does this information translate to game maker?
-- pointer = player and his facing. (Object)
Something = attack (hitbox?)
Angle = angle between those two

6. What are the concrete gml parameters i need, to extract that information?
-- player and facing = player.x, player.y and player.facing (you define facing).
Attack = hitbox' x and y.
Angle = point_direction() with player x and y, and attack x and y.

From there it becomes purely mathematical, as you only work with the player.facing and point_direction, which are 2 angles. The exact code/math is already given by Yal, which you can look up and is not my point here.

Edit: as you might have noticed, another snaller problem is introduced in the process: when is the shield "facing toward attack"? It is a sensitivity (angle range) you need to determine for yourself. This is because you dont want the shield to be autistic and block only at the exact angle toward the enemy (which would be a miracle), rather a range.

Hope this helps you out in the root of your problem. Good luck
 
Last edited by a moderator:
A

ArKeid0s

Guest
Just a little question does it works also in pure 2D when I am asking that I think of Death's Gambit, can I do a shield system like in this game ?
 

Yal

🐧 *penguin noises*
GMC Elder
can I do a shield system like in this game ?
It's possible to make a system like that, but it'd probably be a stretch to promise you can do it :p

(The TLDR is "you can do anything 2D in Game Maker", the hard part is figuring out HOW; and usually it boils down to "break the problem down into smaller parts until you know how to do each one of them" - if you're completely new, I'd recommend doing some tutorials so you get more familiar with what's possible and can figure out how to do some basic stuff, then you can gradually learn building stuff outta that. Check out Shaun Spalding and GMWolf / Fel666's stuff on Youtube for two of the best GM tutorializers)
 
Top