Wednesday, September 23, 2015

Game Design Analysis - Dungeons and Dragon's Concentration Mechanic

To begin, allow me to give a proper explanation of how Concentration works in DnD. I'll be talking about it in from a 5th Edition standpoint but older editions that have Concentration work much the same, the only real difference is that Concentration used to be a Skill where it is now just a Constitution Saving Throw (ergo, the heartier you are the more damage you can take while focusing on your spells).
Muscle Wizards are actually kind of a thing...
So imagine Concentration Spells as if they are tagged with a "Unique" modifier. What that means in game terms is that there can only be one instance of a Concentration spell at a time. So for example say you cast one spell that required Concentration, in order to cast another spell that had Concentration you'd have to cancel/abandon your first Concentration spell.
*Mana not always located in the knees*
If a player also takes damage while Concentrating on a spell then they must make a Constitution Save versus 10 or half the damage you take (whichever is higher). If they fail that save then they lose the spell they're concentrating on. That means if a player is flying high up and they take an arrow to the face they'd better hope they pass that save.
Avoid having this happen
There are some other cases that a DM might require a Constitution Save to maintain spells, however that depends on how 'hardcore' your specific DM wishes to play. Some may only call for it on receiving damage while others may call for it during any stressful/difficult situation, such as while riding on a crazy uncontrolled careening cart or during a oceanic adventure and your character is sea-sick.

---

Mechanical Analysis:
I believe this 'Unique' Concentration system was implemented due to the previous editions' buff mode. What I mean by that is previous editions didn't require Concentration for most buff spells (+AC, +Ability Score, etc) so most fights would start with the Wizard and Cleric buffing everyone to god status and fights would turn into a game of rocket tag (read as: everyone so crazy buffed that the first one to land an attack usually OH-KO's the other). Therefore Concentration was revised to make it so only one of the very useful buff/utility spells can be used at a time.
This change to Concentration makes it so casters can offer up a more unique answer to situations. Certain scenarios may call for Ability Score buffs or maybe something as simple as the ability to fly. With these scenarios smart players can feel like they always have an answer or a mechanic to add to the fight that will tilt things in their favor, but there-in also lies a drawback.

For Arcane casters they would have to go around and gather/memorize all these utility spells and for Divine casters they have to prep their spells ahead of time, so players may fight it difficult or annoying to plan for these situations unless the DM provides them with a pretty obvious clue about what's going to happen. The players have to be creative with the spells they have.
The other main drawback that many players express when looking at Concentration is that it seems too easy to break Concentration (hell, there's even a feat for doing exactly that called Mage Slayer). While I agree that is has become significantly easier to break Concentration, I think that it is a fair balance for casters. In previous editions past level 10 or so with straight casters (like Wizards) get incredibly strong, practically gods compared to the more martial way of fighting (ergo sharp/pointy/bludgeony things).
*Just a rough example, not a perfect demonstration*
Now, with Concentration, Wizards aren't these almighty figures and it brings them down to level with the other classes. They are still powerful but they have to play around certain opponents as well as planning out their spells and that makes combat actually interesting for casters. Instead of holding a person in place magically and flying off while peppering them with fireballs they have to choose between flying or locking them in place before raining the fire.... When talking about it like that it still seems powerful but I promise you it is better to add these limitations to prevent reality warping magic gods from running amok.

Lore Analysis:
In the end Concentration offers up a level of realism that would come with casting magic (I like to think that magic is similar to programming!). Imagine with me for a moment that you're a powerful Wizard and you wish to fly you and your allies up a cliff. Each turn you must mentally keep track of where your allies are in space so your spell can keep them aloft, as well as automatically moving everyone along with the world's rotation (lest your party suddenly become a Mach-1 bullet through the nearby village). That's a lot of math and variables to keep track of. So if you were up there in the sky doing advanced mathematics and some jerk blasts you in the chest with an arrow you may slip up with some of those numbers. And all of that example is just for the spell Fly.

As a DM it is a good exercise in imaginative thinking if you put yourself into the role of a Wizard and figure out why some of these spells have the Concentration tag attached to them. The answer could be as simple as applying an equal force in the exact opposite direction to the force being used in attempting to move (Hold Person); or as complex as stimulating every cell in another adventurer's body to induce a higher state of regeneration or enhancing the spine to increase reaction time and reflexes (Enhance Ability). Simple stuff, right?

Tuesday, September 15, 2015

Directional Hit Detection with Dot Products

Note: Before proceeding with this article, please make sure you have a basic understanding of Dot products as I will not be covering them in this post. That may be a topic for a future article. :)

To begin lets say that you have two objects; one doing the shooting and one being shot. We'll call them Gun (Shooting) and Enemy (Being Shot).


Since all of the math will be calculated around the Enemy we'll first need to get the Vector3 from the Enemy to the Gun, which can be done by taking the Enemy's position and subtracting the Gun's position (Enemy.position - Gun.position). We'll call this variable the Direction Vector



Next we'll have to calculate the Dot product of the Direction Vector around the the Enemy's Forward and Right Vectors. Doing so we can get some values which will help determine which 'quadrant' the Direction Vector is in, which can be used as a basic direction. For convenience I usually put these values into a Vector2, the X being the "Front-Back" value and the Y being the "Left-Right" value.


Now to explain what these numbers actually mean; you may have already guessed what they stand for because of my Front-Back-Left-Right names. So if the X (Front-Back) value is positive that means it is pointing in the same direction as the Enemy's forward, thus it is being hit from in front. And if it is negative then the Enemy is being hit from behind. Similarly, the Y (Left-Right) value works the same; with Right being positive and Left being negative.
Finally just compare the absolute value of the two values (X & Y) and the bigger value is the one that is closer to the point of impact on the Enemy.


Following this article should get you to detect collisions on the cardinal directions (Front, Back, Left & Right). However this can also be taken further to provide omni-directional detection by checking the corner cases. It should be noted that this method only works on 2D collisions, as there is no code to check for shots from above or shots from below (however is some cases those could be considered your Front-Back depending on the type of game being coded).
The following will be some example code; it should be noted that I am generalizing a Dot Product and Absolute Value functions so you'll have to make those yourselves, the first parameter for the Dot Function is the Vector we want to Dot towards and the second parameter is the Vector that we're getting from the Gun (the Direction Vector).

---

Vector3 directionVec = Enemy.Position - Gun.Position;
Vector2 dotVec = new Vector2(/*Front-Back Value*/Vec3Dot(Enemy.transform.forward, directionVec),
                                /*Left-Right Value*/Vec3Dot(Enemy.transform.right, directionVec));
//Front-Back value is greater than Left-Right value
if(AbsVal(dotVec.x) > AbsVal(dotVec.y))
{
//Front
if(dotVec.x > 0)
{
//Shot from the Front
}
      //Back
else
{
//Shot from the Back
}
}
//Left-Right value is greater than Front-Back
else
{
//Right
if(dotVec.y > 0)
{
//Shot from the Right
}
//Left
else
{
//Shot from the Left
}
}