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

Why does mouse.Hit.p give a different value when the camera is manipulated?

Asked by 10 years ago

I made the following script to create rts style gameplay:

01local player = game.Players.LocalPlayer
02local mouse = player:GetMouse()
03local char = player.Character
04local cam = game.Workspace.CurrentCamera
05 
06function ShowPointer(camera, target)
07    for i,v in pairs(game.Workspace.CurrentCamera:GetChildren()) do
08        if v.Name == "Point" then v:Destroy() end
09    end
10    local point = Instance.new("Part", camera)
11    point.Name = "Point"
12    point.Size = Vector3.new(1,1,1)
13    point.CanCollide = false
14    point.Anchored = true
15    point.Position = target + Vector3.new(0,1,0)
View all 31 lines...

You can just copy and paste this script in a new project and it will work as it should, but whenever I add some camera manipulation, the mouse.Hit.p value messes up.

1game:GetService("RunService").RenderStepped:connect(function()
2    cam.CoordinateFrame = CFrame.new(char.Torso.Position)
3                        * CFrame.new(0,30,10)
4                        * CFrame.Angles(-20,0,0)
5end)

Does anyone know how I can fix this?

1 answer

Log in to vote
0
Answered by 10 years ago

After some time of trial and error I found out that if you manipulate the camera then you will have to change its CameraType property to Scriptable.

1game:GetService("RunService").RenderStepped:connect(function()
2    cam.CameraType = "Scriptable" -- Sets the CameraType to Scriptable
3    cam.CoordinateFrame = CFrame.new(char.Torso.Position)
4                        * CFrame.new(0,30,10)
5                        * CFrame.Angles(-20,0,0)
6end)
Ad

Answer this question