Camera Module designed for RTS games (Anchor Point Update)

The most important functions are in the description!
https://www.roblox.com/library/7469828078/RTSCameraModule

https://www.roblox.com/games/7506867798/RTS-Camera-Module

Basically, it allows you to make an RTS camera and manipulate it easier.
Before it’s going to be posted in community resources, i would like to get a review of this module.

Important functions

PrintProperties() - Prints and returns Properties

Update() - Sets your camera position, orientation, relative to stored position and xrotation, with yrotation.

SetCameraAngles(X,Y) - Sets your camera angle to X and Y in common degrees

SetCameraPosition(X,Y,Z) - Sets your camera point position to X , Y and Z

UpdateCameraAngleInDegrees(X,Y,DeltaTime) - Adds X and Y to stored x and y rotations. You don’t need to add a DeltaTime from now.

SetZoom(Zoom) - Sets zoom value

SetScriptable(IsScriptable) - Allows to ignore a warning, if the camera type isn’t scriptable

SetXClamp(Xmin,Xmax)) - Sets max and min angles for x axis in the camera

SetYClamp(Ymin,Ymax)) - Sets max and min angles for y axis in the camera, but it requires YRotationLimit to be true.

To set YRotationLimit to true or false, use
SetYAngleRotationLimit(IsLimit) function.

Less important functions

GetActualZoomWithWhiteList(WhiteList) – has no actual functionality yet. Returns ZoomOut value for now.

Move functions

MoveForward(Speed) - moves camera point forward on z and x axis (y axis is being ignored)

MoveBack(Speed) - moves camera point backwards on z and x axis (y axis is being ignored)

MoveRight(Speed) - moves camera point to the right on z and x axis (y axis is being ignored)

MoveLeft(Speed) - moves camera point to the left on z and x axis (y axis is being ignored)

MoveUp(Speed) - moves camera point up on y axis from world’s orientation

MoveDown(Speed) - moves camera point down on y axis from world’s orientation

MoveUpRelativeToCamera(Speed) - moves camera point up on y axis from camera’s orientation

MoveDownRelativeToCamera(Speed) - moves camera point down on y axis from camera’s orientation

EnableAnchorPoint(Enabled) - enables camera to be set to anchor point

SetCameraAnchorPointY(Y) - sets Y anchor point

InvokeCameraAnchorYPoint(Blacklist,TerrainIsCubic,readingWater) - raycasts to return true Ypos

Here’s an example script

local CurrentCamera = workspace.CurrentCamera

local Module = require(script:WaitForChild("CameraModule_RTS"))

local Sensitivity = 10
local Zoom = 40
wait(2)
Module:SetZoom(Zoom)
Module:SetCameraAngle(10,0)
while true do
	local Y = Sensitivity 
	Module:UpdateCameraAngleInDegrees(0,Y,wait(1/60))
	Module:Update()
end

robloxapp-20210918-1214301.wmv (3.3 MB)
Saddly i couldn’t upload the mp4 version

After the anchor point update
robloxapp-20210918-1300400.wmv (3.2 MB)

4 Likes

This seems really useful however I’m a bit of a noob, I’m guessing you’d bind the movement functions with keybinds using UserInterfaceService?

I’ve noticed while moving the camera especially 2 directions at once things appear blurred because the DeltaTime and MoveSpeed values are a bit jarring for me yet lowering those values fixes the issue but the camera becomes way too slow to be functional, Any suggestions? I’m probably the one that did something wrong. :slightly_smiling_face:

Which functions have you used? :slight_smile:
I recommend using run service for that.

You should have used RunService with this.

It would be better also if you move all logic inside the module.

I always have only global elements accessible to the script. I believe that modules are there to hide large chunks of code.

Also look into actually using RunService inside the module.

Could we see a video of what the module is able to do?

Sure i can use a run service inside of a script, so you don’t need to give me a delta time and make a video of it’s potential. :slight_smile:

Yeah I just used UIS to key bind it to button holds but I’ll try some other things, I’m still learning some of this stuff so I have no clue what the best way to do it is.

https://developer.roblox.com/en-us/api-reference/function/UserInputService/IsKeyDown
Try this

Do you think there’s a way to make the camera height adjust according to elevation below it?
Ex: The camera raises when above a mountain so it’s not close to the camera

I could a function for that, so everything will be kept clean in the main script

That would be pretty cool and thanks for releasing this because I’ve been curious on how to do this effectively for a while and it helps with the learning

So I’ve attempted using RunService even though I know little about it and I guess I’m dumb lol

UserInputService.InputBegan:Connect(function()
	if UserInputService:IsKeyDown(KeybindConstants.MoveForward) then
		Holding = true
		RunService.Heartbeat:Connect(function()
			if Holding == true then
				RTS_Cam:MoveForward(deltaTime,Speed)
				RTS_Cam:Update()
			end
		end)
	end
end)

UserInputService.InputEnded:Connect(function(Input)
	if Input.KeyCode == (KeybindConstants.MoveForward) then
		Holding = false
	end
end)

I must of did something wrong because with this the speed of the camera increases with each press of the “W” key… :upside_down_face:

Try run service.RenderStepped instead of a UIS event

How would I be able to bind the key without UIS though?

you can use my hotkey module module

Oh cool but I’m a bit confused

HotkeyModule.getHotkey(Key)

keeps returning false… I must be doing something wrong

Show me your script, please.


image

local HotkeyModule = {
	Hotkeys={
		
		MoveForward = Enum.KeyCode.W,
		MoveLeft = Enum.KeyCode.A,
		MoveBack = Enum.KeyCode.S,
		MoveRight = Enum.KeyCode.D,
		
	},
	Buttons={},
	MouseDelta = Vector2.new();
}

is this how I should setup hotkeys in the module?

No, you don’t touch the module itself.
You should use the built in functions and put enums in the argument

Alright my bad I’m dumb 1 sec lol

edit: that makes so much more sense thanks for the help

1 Like