After I implemented animations to my character, the attacks broke, they dont go do the cursor because the animation moves the weapon.
I think I can fix it by implementing a line trace beginning from the AttackOri (a scene component directly at the tip of the staff) and ending at the mouse cursor, but I cant figure out how to do it. Is actually driving me insane.
Your Line Trace in the video seems to work properly since the debug line is starting at the tip of the staff and the end at the click location , to me the issue come from the way you define the rotation of the spawned projectile (but it look correct) or maybe you have some outdated code in your projectile
Ok I see may bad, the issue is that Convert Mouse location to world give you the location of the mouse next to the camera so you need to do 2 traces here, one to get the location the first object under the mouse cursor and the second one from the character to the impact point.
You may want to do some refining of the result of the first trace for example to offset it from the ground, check if the result is in valid (if the player is clicking somewhere where you dont want him to attack you could decide to block it) …
Edit : You can check https://youtu.be/b1_efR9hrT4 for detailed information about the node (his video are old but I started with that long ago and I can tell you they are greats
That worked, but maybe my line of thinking is wrong. Since its a top down game, the projectile needs to be always a certain distance from the surface.
The line trace now works, but its acting in a 3d enviroment. I need it to go in the direction of the cursor, but in 2d if that makes sence, so it does’nt go up.
I think a simple way of achieving what you want is to just find the intersection between the ray from the mouse cursor and the virtual plane at your projectile origin location Z (height).
The green horizontal bar is the plane. If we use the Line Plane Intersection blueprint node, we can find the red line vs green intersection. You could use the result as is and then do a linetrace from the green cross to this intersection point. However, I’m assuming that your projectiles have a max distance, or no max distance at all.
So what you want to actually do is normalize this result (the segment from the green cross to the intersection point), so you can then multiply it by whatever max distance you want to use.
Please note that in the above blueprint graph, I’m not checking whether there is an actual intersection with the plane (boolean red ‘Return Value’ output). Depending on what kinds of camera angles are possible in your game, it might be safer to check there is an actual intersection before performing the line trace.
I didn’t mention it in the text but if you look closely at the blueprint graph screenshots, the Plane Normal parameter of the Line Plane Intersection node needs to be set to (0, 0, 1). This is because we’re in a top down game and we can assume the trace will always come from the top. This means we want the plane to intersect with to face upwards (+ Z).
Good question. We’re just multiplying the direction vector by an arbitrarily large value (the direction output of the previous node is a normalized vector, with a length of 1, which isn’t enough to intersect with the plane). The only thing that matters is that this value is big enough to ensure that we do have an intersection with the plane. I put 10000 in this example but you actually need to make sure it is at least the distance from your camera to the projectile origin location.
If you are using a spring arm component for example, it could be the spring arm length x 1.5 (multiplying by 1.5 just to make sure we reach the plane to intersect). Else, you could use the real length of the distance between the camera component and the projectile origin location (again, multiplying by a value > 1 is always a good idea to ensure an intersection).
The line plane intersection node does a simple mathematical check, it doesn’t perform any expensive collision and nothing else of the sort, so having a bigger value than necessary for this multiplier isn’t going to impact performances at all.
Edit: actually, since your game is not a ‘complete’ top down (the camera is at an angle), the above isn’t exactly true. Because the player can potentially click at a ‘grazing’ angle, we need this line distance to be quite a bit bigger than the distance to camera. You should do some tests, in case you notice some intersections are not happening. But I would be you, I would just use a very large value.