How to rotate an ojbject around a pivot point with an offset

Godot Version

Godot 4.3

Question

Hello there, I need to rotate the weapon around the pivot point towards the scope so that the muzzle is facing the scope (like in Starbound). After rotation, the result should look something like the picture below.
strb

The problem is that when using LookAt() the X axis is rotated towards the scope, but the muzzle is not on the X axis. I’m not very good with vectors, so I don’t understand what transformations I should do for the rotation I need.

Try to do something like this:

pivot.rotation = muzzle.global_position.angle_to_point(scope.global_position)

It works, but something seems to go wrong when the scope is close to the weapon

I solved my problem using global transform and local muzzle position relative to the pivot. It went something like this:

pivot.LookAt(scope.GlobalPosition - pivot.GetGlobalTransform().Y * muzzle.Position.Y);

But still, thx for the help

2 Likes

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