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

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

Asked by 7 years ago

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,

01local UserInputService = game:GetService("UserInputService")
02game.Workspace:WaitForChild(game.Players.LocalPlayer.Name)
03local player = game.Players.LocalPlayer --get the local player
04local character = player.Character
05local Mouse = player:GetMouse() --get the mouse
06 
07local headMotor = character.Neck4.Motor6D
08 
09while true do
10    local mouseP = Mouse.Hit.p
11    local direction = (-mouseP + character.Head.Position).Unit
12 
13    headMotor.C0 = CFrame.new(Vector3.new(0,0,0),-(workspace.CurrentCamera.CFrame.lookVector))
14    --print(workspace.CurrentCamera.CFrame.lookVector)
15    wait(0.1)
16end

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

Log in to vote
0
Answered by 7 years ago

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

1local direction = character.HumanoidRootPart.CFrame:toObjectSpace(workspace.CurrentCamera.CFrame)
2headMotor.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

Ad

Answer this question