Hello!
I have an object “hand”, which is a parent of an object “gun”. I need to calculate the rotation angle for the hand so that the muzzle of the gun is pointing at the cursor, but I don’t know how to implement this with a formula. How is it possible to do this?
I have not looked at the attached sample project, but the basics of rotation towards a certain point can be seen in this example:
I think you need to make sure that the point you rotate around is the hand or maybe the center of the gun. Let that point be a game object and position the sprites accordingly.
I added a pivot point to the arm. But I need to rotate my hand to point the muzzle of the gun towards the cursor. I don’t know how to apply the muzzle angle to the arm angle.
You need to calculate the rotation with respect to the “elbow” position, not the shoulder point.
Since it looks like the lower arm is at a right angle (angle C) to the upper arm, you can use the example that @britzl gave, calculate the angle for the shoulder (angle A) and use Pythagoras to calculate angle B.