This is very similar to my previous post, but this model uses bones instead of parts
I’m trying to get this model to rotate and point towards a player. Currently, I am adjusting the CFrame of the entire part to point torwads the player (which is sorta a workaround, but it works), but now I need a bone inside of the mesh to point towards the player.
Now I need this specific bone, called “GunBase” to rotate and point towards the player too.
Here’s my current script, similar to the script in the previous post, and this is the behaviour I get.
-- part refers to mesh, thumpart refers to the humanoid root part of the player, and gunbase to the bone
part.CFrame = CFrame.new(part.Position, Vector3.new(tHumPart.Position.X, part.Position.Y, tHumPart.Position.Z))
gunBase.CFrame = CFrame.new(gunBase.Position, Vector3.new(tHumPart.Position.X, part.Position.Y, tHumPart.Position.Z))
This is what the GunBase bone looks like at neutural
Alternatively, I was thinking maybe I could attach the bone to a separate part, and then change the CFrame of that part. Don’t know how that would work though
Tried trying something from this post, and got this:
part.CFrame = CFrame.new(part.Position, Vector3.new(tHumPart.Position.X, part.Position.Y, tHumPart.Position.Z))
local gunPos = gunBase.Position
local lv = tHumPart.CFrame.LookVector
local dist = (gunPos - tHumPart.Position).Magnitude
local diff = gunPos.Y - tHumPart.Position.Y
gunBase.CFrame = CFrame.Angles(0, 0, (((gunPos-tHumPart.Position).Unit):Cross(lv)).Y)
It almost seems to be working, but not quite right and definitely in the wrong positions. Timesing the CFrame.Angles to the current CFrame wouldn’t work either as that just makes it spin around in circle.
Bumping this thread because after SO MUCH TIME I have found a solution! I don’t know if this will work for others, but it worked for me.
You can use Cframe.lookAt() to make the bone face a part, but for bones you MUST USE WorldCFrame, as using only the bone’s CFrame will set it relative to the bone, and not the world axis. For example, your script would look like: