Camera hard stud limit

You know how games like Apocalypse Rising limit the camera distance by slapping on a ‘Please zoom in’ GUI? Just made a model that resets the position to a comfortable distance behind you. I made a more flickery version a couple years ago but improved it. Anyone know of anything better? (Other than 100% Scriptable. I wanted to keep default Custom.) Video of this in action:

[video]http://www.youtube.com/watch?v=e-CsYUYTaIg

[quote] http://www.roblox.com/Camera-hard-stud-limit-item?id=143605105
You know how games like Apocalypse Rising limit the camera distance by slapping on a ‘Please zoom in’ GUI? Just made a model that resets the position to a comfortable distance behind you. I made a more flickery version a couple years ago but improved it. Anyone know of anything better? (Other than 100% Scriptable. I wanted to keep default Custom.) Video of this in action:

[video]http://www.youtube.com/watch?v=e-CsYUYTaIg[/video] [/quote]

Looks nice, and pretty damn useful. I personally haven’t done anything like that before that hasn’t included the Scriptable camera type, but I would suggest using RenderStepped if you’re not getting an instant-enough action. That may resolve the flickering, but again I’ve never done that kind of thing before, and I doubt that it would be any more instant than .Changed.

Yep I do use that, here’s half the code

rs.RenderStepped:connect(function() if (h.Position - c.CoordinateFrame.p).magnitude >= 14 then p.CameraMode = Enum.CameraMode.LockFirstPerson p.CameraMode = Enum.CameraMode.Classic
It’s just a simple trick haha. There’s probably a much smooth way if you set CameraType to Scriptable and edit it, then set it back to Custom correctly. :>

While it’s a step in the right direction, that hack still jerks noticeably.

I spent some time and figured out a smoother solution that still works well with the default CameraType.

Edit: Try it out here

There’s no visual shaking when you reach the max zoom. However, you aren’t able to use right click to change the camera angle while you are at the max zoom distance. I can’t fix that without using a Scriptable camera. And if you scroll out further than the max zoom, it may take a bit of extra scrolling to finally see the camera zooming back in.

[code] --Put this LocalScript in game.StarterGui :> ~Maelstronomer
–Eliminated jerking ~Merely
p = game.Players.LocalPlayer
c = workspace.CurrentCamera
rs = game:GetService(‘RunService’)

while not p.Character do wait() end
h = p.Character:WaitForChild(‘Head’)

local maxDistance = 14

local lastDirection = c.CoordinateFrame.lookVector
rs.RenderStepped:connect(function()
if (h.Position - c.CoordinateFrame.p).magnitude >= maxDistance then
c.CoordinateFrame = CFrame.new(((h.CFrame - (lastDirection * maxDistance)).p), h.Position)
else
lastDirection = c.CoordinateFrame.lookVector
end
end)[/code]

A bit over obsessed with suspended mono-rails, Merely?

I reconstructed the Custom cameratype entirely using Scriptable, and it has somewhat of a zoom limit.
It is a little wobbly though, so that’ll have to be fixed somehow.

wait(0.03)
local cam = workspace.CurrentCamera
local mouse = game.Players.LocalPlayer:GetMouse()
local char = game.Players.LocalPlayer.Character
local renderStepped = game:service("RunService").RenderStepped
--V USER CUSTOMISABLE STUFF V
local head = char.Head -- change this to the head you're using, be it a fake one or a real one.
local maxDistance = 20 -- Maximum zoom distance
local defaultDistance = 5 -- Current zoom distance (default for spawning)
--^ USER CUSTOMISABLE STUFF ^
cam.CameraType = "Scriptable"
cam:SetRoll(math.pi)
local keys = { }
local mouseDown = false
local distance = defaultDistance
local isFlipped = false
mouse.KeyDown:connect(function(key)
	keys[key] = true
	if keys["i"] then
		if not (distance < 1) then
			distance = distance-1
		end
	elseif keys["o"] then
		if not (distance > maxDistance) then
			distance = distance+1
		end
	elseif keys["f"] then
		isFlipped = not isFlipped
	end
end)
mouse.KeyUp:connect(function(key)
	keys[key] = nil
end)
mouse.Button2Down:connect(function()
	mouseDown = true
end)
mouse.Button2Up:connect(function()
	mouseDown = false
end)
mouse.WheelForward:connect(function()
	if distance < 1 then return end
	distance = distance-1
end)
mouse.WheelBackward:connect(function()
	if distance > maxDistance then return end
	distance = distance+1
end)
function getMouseDelta()
	local old = Vector2.new(mouse.X, mouse.Y)
	renderStepped:wait()
	local new = Vector2.new(mouse.X, mouse.Y)
	return new-old
end
while true do
	if isFlipped then cam:SetRoll(math.pi) else cam:SetRoll(0) end
	local delta = getMouseDelta()
	local pos = CFrame.new(head.Position) * (cam.CoordinateFrame - cam.CoordinateFrame.p)
	if mouseDown then
		if isFlipped then
			pos = pos * CFrame.Angles(delta.y/128, delta.x/128, 0)
		else
			pos = pos * CFrame.Angles(-delta.y/128, -delta.x/128, 0)
		end
	elseif keys[string.char(19)] then
--		print("right")
		if isFlipped then
			pos = pos * CFrame.Angles(0, 1/32, 0)
		else
			pos = pos * CFrame.Angles(0, -1/32, 0)
		end
	elseif keys[string.char(20)] then
--		print("left")
		if isFlipped then
			pos = pos * CFrame.Angles(0, -1/32, 0)
		else
			pos = pos * CFrame.Angles(0, 1/32, 0)
		end
	end
	pos = pos * CFrame.new(0, 0, distance)
	local ray = Ray.new(head.Position, -pos.lookVector*distance)
	local _, hit = workspace:FindPartOnRay(ray, char)
	if _ then
		local distance = (pos.p - hit).magnitude
		pos = pos * CFrame.new(0, 0, -distance)
	end
	cam.CoordinateFrame = pos
end

Enjoy ! :smiley:

Mine flickers back a couple studs when you zoom out too far. Functional but it does only flicker a couple studs, like an elastic band.

Merely’s has no immediate stud positioning flicker but completely stops camera rotation when you zoom out too far. And you have zoom back in extra far.

FiniteReality’s is smooth with a nice SetRoll touch, but has two bugs: Zooming in to first person shows your hats and looking straight down or up will constantly flip and spazz the camera.

<3 this site for having cool discussions like this.

I was playing around and trying do do something similar, and I used part first for testing sake. Well, I got super weird looking illusion:

It looks like I have big part on my head. And since of RenderStepped, when you move the camera, it looks the part is actually there on my head, while it’s actually 1x1x1 part 10 studs away from character in front of camera.

zars: The part is closer to the camera than the player, so it looks larger than the player. It’s the same in real life; you can make your finger be as high as the Eiffel Tower if you’re far enough away from it.

Slightly OT post
Personally I have more patience with the “zoom in to continue” method - it doesn’t feel quite as restrictive; you know that the camera works but the place creator is limiting your viewable area for the sake of better gameplay. That’s easy to understand and deal with.

Just watching that video made me shudder. I’d go nuts trying to zoom out farther and wondering why the heck it wasn’t working - cuz I know the camera DOES go farther than that in other places.
Eurgh. Just my opinion.

-Sidenote
Does anyone else get their jimmies positively rustled when they see how smoothly ROBLOX runs.
It’s just so so so so SO so so much cleaner and smoother and more realisticly plastic-y than it was in 2008.
Oh my. :woohoo:

That’s not the thing. It actually looks like the part is at same position as head, so it looks super funky. Hard to show that illusion in picture.

HanSolo996 I’d take an rubberband camera wall over an annoying slap-in-the-face GUI any day that you can keep zooming out of then you have to needlessly zoom EXTRA far to get back out of it. We need to somehow combine all of our ideas…

Oh, we could also get a CameraDistanceLimit property or something. :smiley:

Heh, I see your point.

[quote]
Oh, we could also get a CameraDistanceLimit property or something. :smiley: [/quote]
…that would actually do it.
Don’t have anything else to say cuz you said it for me. :whistle:

our solution involved a bit more of a shal we say, complex approach. We just kinda locked the mouse with some camera magic and abuse and made our own third person, which in a way has some functionality with unlocked mouses, though it kinda destroys the purpose of it, and moving the camera into first person ‘works’ as long as there aren’t any parts to block the camera view.

Really what we’ve done is practical within our own game environment, I dont think I’d dare put it elsewhere without some serious modifications.

[quote] our solution involved a bit more of a shal we say, complex approach. We just kinda locked the mouse with some camera magic and abuse and made our own third person, which in a way has some functionality with unlocked mouses, though it kinda destroys the purpose of it, and moving the camera into first person ‘works’ as long as there aren’t any parts to block the camera view.

Really what we’ve done is practical within our own game environment, I dont think I’d dare put it elsewhere without some serious modifications.

Strobe | Read Description - Roblox [/quote]

Wasn’t it the CameraMode = “LockFirstPerson” and CameraType = “Attached” shizzel?

It’s actually a scriptable camera and custom camera that we swap back and forth constantly to lock the camera’s mouse, sounds hacky and really is, but it works fairly good when hooked up to renderstepped.

The reason for the camera swapping is roblox likes to wait for the mouse to move until it swaps from classic to lock first person regardless of when you set it, which isn’t ideal, so when you swap cameras you end up changing the mouse lock permissions without waiting for the mouse to move. We got the idea from blobbyblob’s custom first person system.

[sub]mael can you send me this pretty please[/sub]

He put it in his models

A practical solution to the gui-slam-in-the-face that shows what the place creator wants vs. the hidden-camera-wall that makes it look like it is broken is to have the camera wall and whenever one zooms out too far a textlabel comes up saying you can’t zoom out any further.

Btw, is it not possible to have a local invisible bounded box welded to the character? Hm, you would still have to zoom back in though.

Ah dang, I was hoping the distance was customizable. I guess I can always try an alternate solution.