Why do we subtract StartLocation

FRotator TurretRotation = FVector(LookAtTargetCleaned - StartLocation).Rotation();

why do we need do subtract The StartLocation? I mean couldn’t we just put

       FRotator TurretRotation = FVector(LookAtTargetCleaned).Rotation();

I think it would be helpfull if the instructor would explain more things like: does SetWorldRotation act on a global axis or or does it somehow add the given rotation the the object.

1 Like

My suggestion is to actually try it and see. If I remember right, this is a vector you’re trying to get from the turret to the target. The raycast comes from camera, then you’re trying to make sure the rotation is based on the vector from where the tank is (start location) to where the target is in the world. Then the rotation aligns to that new resulting vector. Here i made a terrible paint drawing.

The turretrotation would thus be based off a longer angled down vector, which may have some offset effects you don’t want. The camera is always lined up with the tank though, so it may not be too bad.

vector

To make things easier lets do this with 2D vectors.

Say
Turret’s location is [2, 3]
Player is at [5, 2]

Doing (Player - Turret) will be [3, -1] which is a vector that goes from Turret to Player. Here it is visualised

And you can see that the direction is towards Player

6 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms