Keep Component constantly rotating towards Actor


I’m trying to have my Projectile Spawn Pos constantly update to face the currently locked on target so that the projectile will fire straight towards the Actor. Currently after locking on the Spawn Pos will change rotation to random directions based on where the Third Person Character is facing. I’m guessing something along the lines of getting the relative Pos of the target would work but I can’t figure it out. Any help is appreciated.

Your code is setting a rotation angle (yaw) to a location (in cm). You need to convert the vector between the two locations into a rotation. A convenient way to do so is this (using Find Look At Rotation).

Another option is to subtract your two locations from one another and use “Rotation From X Vector”.

So I used your advice and converted the locations to vectors and it works partially. When the character is angled more than 90 degrees away from the target the projectile fires straight ahead. But when I’m within that 90 degrees it works perfectly. Any idea why it’s doing that.

Updated code

I think this is hard to answer without seeing the rest of the code. What does “fires straight ahead” mean? That sounds like the movement direction is wrong, rather than the rotation?

Maybe “Lock On Engaged” is false and the whole block isn’t executed? I’d recommend to just debug the code and put a breakpoint before Set World Rotation to figure out how the computatinos worked out.

Cheers

Here’s a video showing what I meant, the Lock On Engaged bool is just associated with the entire camera locking system and works perfectly fine with that. I also made the Projectile Spawn Pos visible in game and it shows that it’s staying pointed at the target and firing towards it until it hits around a 90 degree angle. It stays locked but the spawning seems to ignore the direction after it becomes too great. Maybe it’s colliding with the player character or has something to do with overlapping the player.

Found the problem, it was due to the Projectile Spawn Pos clipping into the player character. Resolved it by setting the Projectile BP to ignore Pawn collision.