Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Need help with rotating a object to face the players lookVector?

Asked by 3 years ago

I'm trying to make it so the shield is facing towards the direction the character is facing, but rotating it is not working! I've tried BodyGyro, HingeConstraints, Etc. I really just want to rotate it the way the character is facing, right now the CFrame is set correctly, but the shield is facing down, towards the players feet. Below is the portion of the script where this takes place, any help would be greatly appreciated!!

local Shield = game:GetService('ReplicatedStorage'):FindFirstChild('Shield'):Clone()

Shield.Name = "TS"
Shield.Parent = Player.Character

Shield.Part.CFrame = Player.Character.PrimaryPart.CFrame * CFrame.Angles(math.rad(5), math.rad(5), math.rad(5))

1 answer

Log in to vote
0
Answered by
Speedmask 661 Moderation Voter
3 years ago
Edited 3 years ago

this is how I adjust CFrames to look vectors

local UP = Vector3.new(0, 1, 0)
local lv = PrimaryPart.LookVector
Shield.CFrame = CFrame.fromMatrix(PrimaryPart.Position, lv:Cross(UP), UP)

however why don’t you just forget about look vectors and instead set the shield ToObjectSpace on the player to then offset it forward? that’s just another idea but I expect this should work :)

0
Lol, every time I run this script it literally just kills my character. haha JayShepherdMD 147 — 3y
0
yeah, I forgot to add the position, sorry about that! although, I am not sure why that would kill the character. Speedmask 661 — 3y
Ad

Answer this question