Rotating local transform towards a world point

I have a turret transform which is a child of weapon game object. Which in itself is a child of player object. I want to rotate this turret towards a world point (Raycasthit.point of a ray going forward from center of the screen). I tried the usual Quaternion.LookRotation method by subtracting raypoint from turret local position,from world position and even by converting the raypoint from world to local by InverseTransformPoint and i also tried changing the world up direction to every possible combination. I also tried SetLookDirection method with every possible combination. But i just can’t seem to make the rotation work properly. One thing to note is that weapon model is made in blender and turret bone have a default rotation of (90,0,0). Could someone please please please help me with this. I’m stuck with it since last few days.

Just take care of that action by parenting it under another GameObject, and then rotate that GameObject. With Blender-created stuff you kinda wanna always be doing this or you will drive yourself nuts with rotations.

1 Like

But If i put the turret bone inside an empty game object It will break the animations rig right ?

Changing one thing in software often requires changing something else.

Fortunately it is all SOFTware, which means it is SOFT and can be changed.

Okay. Thanks for the help :slight_smile:

Keep in mind that if you are driving a property with an animation, the animations always win.

What I mean by that is if you make an animation to move something, then try to move that thing in code, it will be as if the code did nothing. It is up to you to ensure that properties you want to control in code are NOT driven by any of your animations.

1 Like

Yes that’s right. Thanks again :slight_smile:

Kurt, keep in mind, this is all SOFT. :slight_smile:

Here’s a rundown of how IK overrides animations (and you can too), which I wrote a couple years ago. https://discussions.unity.com/t/740350/2

1 Like