Hello there!!!
I am trying to figured out how the targeting systems works in games like the prince of persia the sand of time or batman arkham series, where you choose a direction with your keyboard or gamepad stick plus the attack button, and the player does not only attack in that direction, he also targets the closest enemy in that direction and of course attack him.
There almost no documentation on this kind of combat gameplay and i have a pretty good idea of how this work but i got stock on the targeting part. Any help will be great(i rather it to be on c++, but also in blueprints will be fine).
Thanks very much!!!
you can use Dot product to compare the orientation of normalized vectors. a dot product between 2 vectors will give you a score between -1 and 1 representing the similarity between the vector’s orientation.
so subtract your pawn’s location from a potential target’s location, to get a vector pointing from pawn to target. then normalize this vector. then dot product this with the forward vector of your pawn’s rotation.
do this for all targets, and the target with the highest dot product will be the one closest to the front of your pawn, but you may want to factor distance into the calculation, so closer things have higher priority. you can do that by multiplying the distance of a target by a small fraction, then subtracting it from the dot product score.
OK thanks!!!
But what about a box or something, that rotates around the player depending on the input direction and also on where the camera is looking, and when this "box " detect an enemy lerp to him when the attack button is pressed. I would like this kind of behaviour, because my player alerady focus on the closer enemy.
I also have this “BoxTrigger” i’m talking about but i havent been able to rotate it in the input direction.
If the method i’m suggesting is even posiblle i would like to know.
But i also try this. Thanks a lot
to rotate an object relative to the camera orientation and joystick input is easy. just take the camera’s rotation’s forward vector multiplied by the MoveForward input axis value, and add it to the camera’s rotation’s right vector multiplied by the MoveRight input axis value. normalize that vector, multiply it by the distance you want the object to orbit at, and add it to the pawns location. that will give you a location that orbits the pawn and rotates to the input direction.
to make sure you are only orbiting on the XY plane, you should probably zero out the roll and pitch values on the cameras rotation, before getting the forward and right vectors.
but anyway, the dot product method i mentioned before is perfectly accurate in all scenarios, while your collision method would have a bias that prefers targets that are on the edge of the collision primitive, instead of preferring targets that are centered to the orientation. imagine 3 enemies right in front of you, and all 3 are touching the collision primitive. if you look left and right, the chosen target would oscillate between the left and right enemy, ignoring the center enemy, because the center enemy never ends overlapping.
Im sorry to keep bothering you, but , if is not to much to ask, colud you show me this in code. Because english is not my main lengauge, i get a little bit confuse, but i believe this exactly what i need. But if you dont is ok
Thanks a Lot!!!
Thank a lot this is very helpfull!!