Aiming a barrel not in-line with the center of rotation

I need help with accurately aiming a gun where the barrel does not aim through the center of rotation.

What are some ways I can accurately aim the barrel at the red part while still rotating the barrel from the green dot?

2 Likes

Nevermind I figured it out. https://gyazo.com/4fafb9be121ba7476843f97c24a1b990

When you’re posting a statement saying that you fixed something (likely on your own) it is good practice to describe what brought you to the fix and specifically what you changed.

This helps users in the future that are looking for a solution to the same problem. Instead of finding helpful advice on this post they’ll get a gif of the working product.

1 Like

Sorry I was in a hurry. Here’s the steps I used.

  1. Using a regular CFrame.new(Center of Rotation, Target) will set the turret pointing towards the Target in the configuration above with the Barrel parallel to the target.

  2. In my case the Barrel was at a fixed height above the CoR. This height can be used as the radius of a circle where the barrel will always be tangent to.

  3. If we measure the distance from the Target to the CoR and we know the target is in-line with the CoR we can use basic trigonometry to solve for the Angle of Depression

tan(Height / Distance)

  1. Now that we have the AoD we can just multiply the CoR by a CFrame Angle with the negative angle and that will put the barrel in-line with the hypotenuse of the right triangle formed.
2 Likes