Problem with LineTrace

I’m rotating my character towards enemies when the player clicks on them.

After the rotation, the character is shooting enemies. I’m handling that with LineTrace by Channel.

The problem is that in this way, the character can only shoot enemies on the same height (so he can’t shoot enemies above or below him).
Any suggestion on how to solve this?

Thank you :slight_smile:

Use a box trace

You programmed the node to do a line straight out from the player. If you want it to end elsewhere, you need to specify the location of the target in the ‘end’ vector.

I also tried to use the mouse cursor as the end point:

But that ends up being a bigger problem: most of the times, the line trace is off to where it should be…
LineTrace Off.jpg

But that has the same problems as the line trace

This could be because of how rotation is set. Are you sure you got that right? You could always add a scene component and make it face “the right way” and use that as a start point…
Anyways since you click on the enemy actor I’m assuming you have a reference to it, so why not pull the world location of enemy and use that as end point for line trace? Just a thought.

Thank you very much for your suggestion! I fixed the problem by adding a scene component and using its rotation to point the target.

You were right about the fact that the rotation was not right… but I had to rotate the actor only in the X/Y axises (a rotation in the Z axis makes the actor bend, which is just horrible). Ideally, one could handle that by breaking actor’s body in lower body and upper body, then make only the upper body rotate… but that takes a ton of work to set up properly… and it’s not necessary for my game mechanics.

Thank you again!