Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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 :)

2 comments

0

Lol, every time I run this script it literally just kills my character. haha

0

yeah, I forgot to add the position, sorry about that! although, I am not sure why that would kill the character.

This discussion is preserved as it was. New answers, comments, and votes are closed.