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

problem pointing my dragon's head torwed screen lookVector when character model rotates?

Hey guys! Am making a dragon! I've got this guy flying around with no animations yet so he is looking pretty stiff. So I decided to make his head move by facing where the screen faces.

basically, am using the motor6D's (in the head) cframe and setting it to point at the Camera.CFrame.lookVector. This works perfectly... until the dragon character turns then the head's rotation is off by how much the character turned from its original orientation.

Da Code,

local UserInputService = game:GetService("UserInputService")
game.Workspace:WaitForChild(game.Players.LocalPlayer.Name)
local player = game.Players.LocalPlayer --get the local player
local character = player.Character
local Mouse = player:GetMouse() --get the mouse

local headMotor = character.Neck4.Motor6D

while true do
	local mouseP = Mouse.Hit.p
	local direction = (-mouseP + character.Head.Position).Unit

	headMotor.C0 = CFrame.new(Vector3.new(0,0,0),-(workspace.CurrentCamera.CFrame.lookVector))
	--print(workspace.CurrentCamera.CFrame.lookVector)
	wait(0.1)
end

If anyone has ANY thoughts on how to cancel out the difference in rotation please let me know below. Maybe there's some way to make the rotation in local space or something? Plz help bring my Dragon to life! :D

1 answer

It took Two hours but I got et!!! :D used this little code right here

	local direction = character.HumanoidRootPart.CFrame:toObjectSpace(workspace.CurrentCamera.CFrame)
	headMotor.C0 = CFrame.new(Vector3.new(0,0,0), direction.lookVector)

Now my dragon can stare in the same direction of the screen even when the character changes orientation :D

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