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

The lookVector resets?

Asked by
drahsid5 250 Moderation Voter
9 years ago

I'm working on a ThirdPerson Camera, I'm trying to make a 'orbit around the player with your mouse' effect (A normal third person camera) everything is going fine and all, except the camera resets to the default position after moving. Can anyone tell me why?

So far I've tried to divide the mouse position by the screen's resolution (X,Y) That worked, except I wanted to lock the mouse. So I decided to use the new input framework and use the speed in which the mouse was moved, while the camera was locked. I got it, except the lookVector seems to reset to a default value?

My code:

local power = Vector2.new()

while wait(1/60) do
    cam.CoordinateFrame = (Player.Core.CFrame+Vector3.new(.1,2,5))

    game:GetService("UserInputService").InputChanged:connect(function(inputObject)
    power = Vector2.new(inputObject.Delta.X/10,inputObject.Delta.Y/10)  
    --print("delta is (" .. tostring(inputObject.Delta.x) .. ", " ..  tostring(inputObject.Delta.y) .. ")")
    end)

    cam.CoordinateFrame = (Player.Core.CFrame+Vector3.new(.1,2,5))*CFrame.fromEulerAnglesXYZ(cam.CoordinateFrame.lookVector.Y+power.Y,cam.CoordinateFrame.lookVector.X+power.X,0)

end

As you can see, I get the speed (I defined it as power) in which the mouse is moving, then attempt to change the camera's CFrame by an offset (So you can see the custom player) then attempt to change the angle (lookVector) in which the camera is facing by the speed (power) in which the mouse had moved, while adding the old lookVector values.

1 answer

Log in to vote
-1
Answered by 9 years ago

I believe you will need to set the CameraType to Scriptable. Like so:

local power = Vector2.new()

cam.CameraType = Enum.CameraType.Scriptable

while wait(1/60) do
    cam.CoordinateFrame = (Player.Core.CFrame+Vector3.new(.1,2,5))

    game:GetService("UserInputService").InputChanged:connect(function(inputObject)
    power = Vector2.new(inputObject.Delta.X/10,inputObject.Delta.Y/10)  
    --print("delta is (" .. tostring(inputObject.Delta.x) .. ", " ..  tostring(inputObject.Delta.y) .. ")")
    end)

    cam.CoordinateFrame = (Player.Core.CFrame+Vector3.new(.1,2,5))*CFrame.fromEulerAnglesXYZ(cam.CoordinateFrame.lookVector.Y+power.Y,cam.CoordinateFrame.lookVector.X+power.X,0)

end
0
It was already set to scriptable in the function that spawns the custom player. drahsid5 250 — 9y
Ad

Answer this question