Was this intended or is it a bug?

Hi eveyone,

Not a native English speaker so any correction will be well receive ^^.

At the end of this lecture I notice what I think is a bug. I did the challenge without watching Ben’s solution, which lead me the different behavior between his code and mine.

He promotes the AimDirection method variable to an instance variable on the header file and then, on every frame that is not reloading, compares both the AimDirection and the Barrel current forward vector. But if you point your mouse looking to the floor (almost looking the tank above), you’ll notice that the aim pointer never changes to green (Locked). Debugging I notice that the reason is that AimDirection decreases way more than the barrel can (due to the rotation clamp made lectures ago), resulting in never been equal the AimDirection and Barrel current forward vector, hance never changes to green).

My solution was to create an instance variable that would store the last forward vector of the Barrel, initialize it on the Initialize method since not necessarily on the constructor/begin play methods the Barrel reference will be available and on the IsBarrelMoving method update that variable to the current barrel forward vector after doing the comparison. With this approach, even if you lower the camera to point on angles your barrel could never rotate, you still set you aim pointer to green since both vectors (The last know vector and the current one) will be equal.

So basically the question is what the title says.
Was the behavior resulting from the lecture code intended or is it a bug?

If you would like to see more about my solution I’m more than happy to share the code.

Thank you :smiley:

Thanks for asking this. If you’re aiming at the floor you can’t fire surely, so it seems OK. We will be changing the aiming code to quaternions shortly so that barrels take the shortest aiming path so I’ll revisit then

1 Like

Thanks for the quick reply.

I’ll change the code to match what you have then.

Thank you very much! :smiley:

You’re welcome

Privacy & Terms