Hi,
I’m making a top down game where the player controlled with the mouse and having trouble rotate my character to face the enemy.
I made a base enemy blueprint and a few child blueprints from that to create different enemies and made an actor class array in the base enemy bp, but when I attack them the character only rotate and look at to one enemy even when my character attack an other enemy.
Here is my bp for rotation:
You’ve coded it so the player only ever looks at the first base.
I know it that this code will work that way. It’s just a temporary solution. I even tried to only face the closest enemy as well but that didn’t work either. I just don’t know how to make it work that’s why I asking for help.
Ok, I see.
You do have to decide how you’re going to run it.
Options include
-
Nearest
-
Rotating choice
-
One that most recently hit you
etc.
Then you use that lookat node to point the player at that base, until the choice changes again.
What sounds good to you?
I want the character to rotate to the last clicked actor, go there and attack. I have changed my code like this:
It works with the rotation but does not differentiate between enemies from the array, like I standing next to enemy1 and clicked on enemy2 the player starts attacking even enemy2 is out of range. And when I click somewhere else the character walks in there fine, but still facing the enemy.
I think this whole chunk is doing nothing
What’s wrong with just the bottom half, without the gate? And I think it will work better on tick, rather than using the ‘turn to enemy’ event.
Thank you,
I removed the top half of the code and now the rotation is working.
The only problem is still not differentiate between actors. Attacking Enemy1 then clicked on Enemy2 the character attacks first because still in the attack range of Enemy1 then move to Enemy2 and not attack after arrived unless clicked again.
This is my code for attack and move:
I just want it to move to Enemy1 when clicked and attack, then when clicked on Enemy2 stop attacking Enemy1 go to Enemy2 location and attack Enemy2.
Moved the Turn To Enemy as you said but still the same.
I think the problem is with the collision for the attack range, I casted to the Enemy Base and it not differentiate the 2 child actors (Enemy1 and Enemy2). Just don’t know how can fix that.
Sorry, I’m missing something. It’s attacking the one you chose.
Rather than using a massive collision component on the player to determine distance, you can just use
I made this code using your’s:
I wasn’t sure how to link the actors so I used Get Clicked Actor.
It works perfectly but always get error messages for the Branch node.
What is the error? About ‘none’? If so, then you need to check the thing coming out of ‘clicked actor’ is valid.
I put Is Valid node after Get Clicked Actor and now is works.
Thank You
Great