- Home /
The question is answered, right answer was accepted
Have An Object Rotate Around Transform A So That Transform B is Looking at Transform C (C#)
I have a player holding a rifle. In this rifle Game Object there are two transforms. Transform 'A' for the point which the butt-stock of the rifle meets the player's shoulder, and Transform 'B' which is aligned with the weapon's barrel.
Outside of the rifle Game Object there is Transform 'C', this transform is a Ray cast intersection, this represents what the player is looking at. I already have this done.
The rifle needs to rotate around Transform 'A' so that Transform 'B' is always pointing at Transform 'C'.
I had tried messing around with Quaternion Look Rotation, but got completely lost. I'm having a hard time finding a place to start.
Any help greatly appreciated (in C#), thanks.
Here are some diagrams:
Create a new empty game object and add the rifle to it as a child. $$anonymous$$ove the rifle so that point A is at the pivot point of the parent object. $$anonymous$$ake sure the rifle points into the direction of the Z-axis of the parent.
Then transform.LookAt( pointC.position ) should make the rifle point at the target.
Follow this Question
Related Questions
Child transforms screwed up by parent's rotations 1 Answer
How to clamp the rotation of this? 0 Answers
Get slerp to work just as LookAt(,Vector3.right) does 1 Answer
Object slope rotation issue 0 Answers
Unity Rotate Raycast on Quaternion 1 Answer