I’m implementing a wire guided missile which follows players crosshair. I tried to implement it two different ways.
One way was projecting missiles velocity onto cameras forward vector and subtracting it from the current velocity. Problem with this one is the missile only alignes its own forward vector to match cameras forward vector. Hence flying in offset (near the crosshair) when moving the crosshair to new target.
Another way was finding the closest distance from the missile on to a line made from the cameras forward vector. This makes the missile to adjust the offset towards the crosshairs direction only resulting in a mindless wobbling.
I feel I’m not far away getting this right. But I’m clearly missing a piece here.
You could do a trace line from the camera to a forward vector point i.e. 5 meters away and use this vector. Check if the Hit Result is False to be sure nothing is blocking it.
Im on mobile atm, but had this idea to project the missile location onto a plane defined by the camera location, forward vector being the plane normal and subtract the resultant from the velocity. I’d still need to smooth out missile’s angle when getting closer to the cameras forward vector, which I’m not sure how to do
You can check for the distance between the player and the missle by getting the Location of both, subtract them, then use a Vector Length, from the float pin <= 200 is true → move missle.
200 is reflecting 2 meters.
To avoid doing this on each tick, You could start a TimeLine from begin play and create a custom node (i.e. called RestartTimeline) and connect this to the Start execution pin. Then in the timeline add a Event Track (call it i.e. CheckDistance), add a pin by shift clicking on the timeline. Set one for example on each second (leaving the default Timeline length on 5 seconds).
Then back in the Event Graph, you should have a new output Execution pin called CheckDistance. Connect this then to the Branch that checks the distance.
From the Completion execution pin, add the RestartTimeline node you made earlier.
This results in looping the Timeline to check the distance between the player and the missle every second.