How can I make the character I am controlling attack when clicking an enemy in a game with MOBA-style controls?

The setup I have thus far is this:

  • At the begining of the game player posses the camera; they can edge pan and zoom.
  • The player also posses a character on the map. I followed an RTS tutorial that included being able to select different characters to control. So, normally, nothing would be possesed at the begining, until something is clicked, however since I will only have this one character I assign it to the player at the begining.

-In the TopDownController I have code that checks what is clicked and then stores that code in a variable. I used print string to verify if it is identifying the enemy blueprint correctly and it is. I am also quite sure that the variable gets filled with that actor.

-In the TopDownCharacter blueprint I have a function to attack. I takes a target, does AI move to, then plays an animation for attacking.

-I have connected with a blueprint interface (though I am not sure if I did that correctly)

What I was trying to do was at the end of the code in the controller, call the Attack function from the Character blueprint. I.e. Controller identifies target, then character attacks target.

Here is what I have thus far:


When it comes to referencing these two codes to one another I don’t really know what I am doing. I think the rest of the code should work as expected once they have the right references. What should I connect to the target of the Attack Actor function, and what should be connected to targed actor in the AI move to? Or is this setup wrong, and there is a better way to do it? I would appreciate any advice.

In the controller you clicked an actor And sent it to character. It’s on the event “attack actor”in your picture.you didn’t use it. You used the enemy reference variable.

The enemy is who I want my character to attack, that’s why it is plugged in as the target. Should I target the enemy another way?

1 Like

It’s confusing as heck :innocent: :

image

Rename it so you can avoid ambiguity::

image

Those 2 are plugged in in the wrong order. You are sending this message to the Character and telling it that the Hit Actor is the one attacking. This naming convention is clearer:

image

1 Like

The problem is you plugged in the enemy.but didn’t take it out to use.

and the variable name is kind of confusing…I would name them like ,target enemy,target player,selected enemy,etc.