New Guy Needs Help

I made a new BP class that extended UE4’s “Character” called ZogzogsGameCharacter and I made a BP enumerator called “AttackDirection”. Within the ZogzogsGameCharacter I created the function “Attack” and added those 2 inputs you see in my picture.

You can see here how to work with enumerators, pull out from the node and type in “Switch On” and find the one that corresponds to your enumerator’s name. From there you can do things based on the result.

I’ve also included an example of what “Target” means. You can see I have two GetActorLocation nodes. This is a function that all Actors in UE4 get. In one case the Target to call the function is empty so this is run on the owning actor. The second one is called on the actor that was passed in the parameter.

Lastly the math you will have to do next is a bit complex and math isn’t my strong point. You will need to get the degrees between these two actors as a single number from 0-360 (or some range like that) then you take 360 / 6 (number of attackable directions you have) and figure out which direction this actor is being attacked from.

I’d google this with searches like “Find the angle in degrees between 2 actors UE4” and see what comes up to find a BP solution.

The trick is that you will be getting actors rotation in 3d space which is 3 values but this is way overkill for your system since you only care about rotation on one axis (similar to how game characters can only turn on one axis, but a space ship game can turn on all 3.) YOu will want to take the rotation and strip away 2 of the axis so you only have the one you need, which i believe would be “yaw” then use the 2 yaw values to get your final degrees. Use print nodes along the way to get a gist that the math is doing what you want.

2 Likes

Thank you. That was very helpful. I’ve learned a lot. The math I can do, not a big problem. Though I am still a beginner. I was much better at Unreal Engine in the past, but I lost heart because I thought: “Who exactly am I making games for anyways?” But I guess the answer to the question is, everybody. The game is for everybody. I like to play Japanese games made with the Wolf RPG editor, and these people make their games free for everybody to enjoy, so I’m slightly inspired by their attitude, though making a game with an engine such as the Unreal Engine is a hell of a lot more difficult than working with a drag-and-drop RPG editor.

1 Like

Happy to help. I’ve been working on a way way overly ambitious ARPG game which I never finish for close to a decade now. I’m stuck in an infinite purgatory endlessly remaking and improving things over and over. Eventually i just learned all the UE systems etc banging my head against them for years.

3 Likes

Although this is off-topic, mind if you share some screenshots of your game or a link to your Youtube (if you have one)? I still have more questions to ask, and people know me for this – that I never stop asking questions.

1 Like

I understand your wish to keep your work private. I myself don’t care if anybody steals my ideas. Now I have a question, and which is about the “attack direction” enumeration you created; so, what exactly is written in there?

Mechanics and game design solutions i don’t worry about, but branding, UI theme, certain models or creatures. I have seen these situations happen before as an example take a name for a game, if people discovered that you might be interested in they will poach the domain name and hold it from you for 2000+ dollars. Similar things could happen to brand designs being held for ransom. Basically I don’t want to hit a point where I get outlawyered by some sinister dishonest company that makes it’s profits through treacherous means. There is a “game” company that has copyright dominance over the word “Edge” or “Blade” and they don’t even release games of have a franchise they just make all their money from sueing every game that has the word they have trademark control over.

Here is the inside of my enumerator. Click the NEW button to add on a new entry. An enumerator is just a byte number but it gives you the ability to assign a human friendly word to each one. So for anything you want to code where each number is a certain thing like 0=Windowed 1=FullScreen 2=FullScreenWindows, instead of the human that is programming having to remember what each number represents there is a word assigned to it. UE4 gains some special benefits in BPs from using these sometimes too over just regular numbers or words.

this enumerator gets seen by UE simply as AttackLeft=0 AttackCenter=1 AttackRight=2

2 Likes

I see now, so, there is some nefarious “businesses” going on. Now I’ve created the enumerated values (attackleft, attackcenter, attackright.) Sorry for being a total noob, but what do I do now that I’ve got these outputs?:
2582

I was more so just showing how you could interact with enums and you could use that branch to solve the problem but if I was in your shoes I’d do some math instead.

At this point there are countless ways to solve the problem so there’s no right or wrong way to go from here. I’ve made a quick mock up of what I would do keep in mind I made two dummy functions that require some math that I wouldn’t be able to figure out without doing some research:

(These are both fictional nodes that I made just to demonstrate the steps, you’d have to fill in the internals to make them accomplish what they are titled.

The first dummy function "Math That Converts Two Transforms to Degrees would calculate an angle from the 2 transforms and output a float from 0-360 or maybe 0-1.

The second Function Convert Degrees to AttackLocation would most likely just be a large branch statement

If Degrees < 60
return AttackLocation1
else if Degrees < 120
return AttackLocation2

etc.

This could possibly be done in a much more elegant way without so many IFs using the % modulo operator but for now a branch will do.

What I do after that looks a bit silly.

Step 1: I take the enumerator from AttackDirection which is 0-3 and convert it to an integer (so it can go into the negatives) I then minus 1 from it using --. This results in it being -1 to 1.

Step 2: I take the enumerator output by the “Convert Degrees to Attack Location” and convert that to a byte.

Step 3: I add the Result from attack direction (Currently anywhere between (-1 to 1) to the byte of AttackLocation [0-6] offsetting it by 1 to the left or right.

Step 4: Do a series of checks if the number has wound up below 0 or above 6 and adjust if so.

Here is the second enumerator i made:

2 Likes

Sh*t just got real. Though I’m glad you’re helping me study game design out of your own free time. I’m trying to keep up!

1 Like

To simplify think of the AttackDirection just an an offset. If it’s left you -1, if it’s right you +1. Once you calculate the AttackLocation based on the location of the two actors you just have to adjust it by 1 up or down if needed based on the AttackDirection

2 Likes

I was a bit ahead of myself, 'cause I already made a second enumeration. In yours you forgot in your second enumeration that the player can attack the enemy’s right side and left side. So, a total of eight enumerators is correct. As can be seen below:

1 Like

8 directions mirroring cardinal directions sound a bit easier to keep in mind, i was getting caught up mentally a bit plotting the 3 in front and 3 in back as my brain wanted to have a west and east direction, players might encounter the same thing so I think this is better.

You have to rearange them however for my code to work, the sequence matters since it offsets them by +1/-1. RightSide should be between FrontFieldOfAttack3 and BackFieldofAttack3 and LeftSide should remain where it is.

Renaming them by cardinal directions or something like that might make things clearer.

2 Likes

I agree on the cardinal directions being a better naming choice. I understand why I need to change the arrangement now. However, I must mention that one of the essentials to the game is choosing where you’re going to attack at the enemy by pressing the 1, or 2, or 3 key(s). How would I go about getting such a thing done?

Set up input first under EDIT (Top header bar) > Project Settings > Input. Add the buttons for Attack Left, Attack Center, Attack Right.

Do this graph in the ZogzorGameCharacter blueprint on the EventGraph not inside a function.

I used Left, Jump and Right but don’t use these, i just put them there for the example, Use the inputs you add for AttackLeft, AttackCenter, and AttackRight.

GetViableTargetToAttack is a dummy function you will have to fill in. It should do two checks, get all ZogzorGameCharacters currently on the map, do a GetDistanceTo() to each one to see if they are in attack range, then do a check to make sure the player is facing any of them, however many are remaining you will have to do some addition criteria, ie: picking the very closest or most central. Return false if nothing is in range so the game knows you can’t attack anyone.

After that it’s easy, if you can attack someone then just run the attack function we made and plug in the target that the function decided.

2 Likes

"(These are both fictional nodes that I made just to demonstrate the steps, you’d have to fill in the internals to make them accomplish what they are titled.

The first dummy function “Math That Converts Two Transforms to Degrees would calculate an angle from the 2 transforms and output a float from 0-360 or maybe 0-1.”

So what nodes do I put in place of the dummy nodes?

OK, so here’s the deal:

#1 I need to get it so that when the player has decided to attack at an enemy’s space by pressing buttons 1, or 2, or 3, and then left clicks, that he attacks at the selected space.

#2: I need to get it so that the circles that surround the player act as indicators of a player being in range in order to attack.

#3: I need to bind my health system that I created with the attack system.

How stupid of me that my game graph says “right click” as opposed to “left click” – I haven’t noticed this for all the years that my graph has existed … seriously. Anyway, if anyone wants to help out, then please do chime in, as I need all the help I can get to get this game rolling!

Hi Zogzor, I’m traveling on business, when I return I will check in and help some more.

The health system should be handled in the ZogzorGameCharacter. In a simplistic sense each character has an int variable, within the attack function that we made subtract from the AttackedCharacter a certain amount of health, as things get more complex you would process mitigation and parry etc. all within that attack function and if needed you would minus from health.
Within the Attack function we made we have access to both the attacker and attacked character so we can adjust their values and handle everything there since it has everything we need.

The math to get the rotation angle in degrees between 2 actors is too complex for me. I’d start using GetRotation() of both, breaking the rotator out to it’s struct and pulling out just the Yaw value. I’d substract the two Yaw values from each other and see if it’s returning a proper angle in degrees between the two. I’m not sure this would work exactly but it’s a place to start, you can print the value of the float to see if circling around the opponent it is sort of reflecting the angle in degrees that we need and if not can do some trial and error on the math until it does give you the value in degrees.

With this math done the core of your game would be complete (It’s not super complex math most likely just 4 or 5 nodes, but the math is not my strong point). Once you get this value you can use it both for completing the combat system and on tick lighting up the orbs that you want lit up.

This is how i would approach it, I’m not sure at all that this math would work but I would use the PrintString node to start debugging the output and moving pins around, changing + to - etc. until it starts to give the value I want.

Personally I would not make attacking take 2 inputs. Perhaps there are more complex mechanics to come that are making you require this?

1 Like

Your help is much appreciated. You’ve practically been a co-developer to me. I hope to see you again soon!

1 Like

Anyone who can tell me what this node is and how to create it? I’ve been trying to find out what kind of node this is for hours:
Unknown Node