I'm trying to make a custom movement system for Roblox scripting. The game is that you are a pet and shoot other people. I want to make a camera kind of like in Brawl Stars, where it's locked in 3rd person and is kind of a birds-eye view with a slight tilt. I want the character movement to be like it Brawl Stars, too, where when you move in a direction your character faces that way and walks in that direction. Can you help?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Sure, I can help you set up a custom movement and camera system in Roblox that's inspired by Brawl Stars. In Brawl Stars, the camera is locked in a third-person, slightly tilted birds-eye view, and character movement is direct: when you input a direction, the character faces and moves that way relative to the screen.
In Roblox, we'll achieve this by:
Customizing the camera: Locking it to a birds-eye view with a slight tilt, always following the character.
Handling movement: Overriding the default controls to ensure the character moves and faces the direction of input relative to the camera. Roblox's default Humanoid movement is somewhat similar, but we'll make it more precise to match Brawl Stars.
This setup assumes you're using a standard Roblox character (with a Humanoid) for your pet. If your pet is a custom model, you might need to adapt the movement code slightly.
Step 1: Set Up the Camera
We'll use a LocalScript to make the camera follow the character from a birds-eye perspective with a slight tilt. This will lock the camera in place relative to the character.
Create a new LocalScript in StarterPlayerScripts (or StarterCharacterScripts if you want it per character). Here's the code:
lua
-- LocalScript: CustomCamera.lua
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable -- Lock the camera so we can control it
local function updateCamera()
if humanoidRootPart then
local cameraDistance = 10 -- Horizontal distance from character
local cameraHeight = 15 -- Height above character
local tiltAngle = math.rad(30) -- Slight tilt (e.g., 30 degrees downward)
-- Calculate the camera's position: above and slightly behind the character
local cameraOffset = CFrame.new(0, cameraHeight, -cameraDistance) * CFrame.Angles(-tiltAngle, 0, 0)
-- Apply the offset to the character's position and make it look at the character
camera.CFrame = humanoidRootPart.CFrame * cameraOffset
camera.CFrame = camera.CFrame * CFrame.lookAt(camera.CFrame.Position, humanoidRootPart.Position)
end
end
RunService.RenderStepped:Connect(updateCamera) -- Update the camera every frame
What this does:
The camera is positioned above the character (e.g., 15 studs up) and slightly behind (e.g., 10 studs back on the Z-axis).
It applies a downward tilt (30 degrees) to give that birds-eye feel without being completely top-down.
The camera updates every frame to follow the character, keeping the view locked.
You can tweak the values (like cameraDistance, cameraHeight, and tiltAngle) to fine-tune the view. For example, increase tiltAngle for more tilt or adjust cameraDistance for a wider view.
Step 2: Custom Movement System
In Brawl Stars, movement is screen-relative: if you input "up," the character moves toward the top of the screen and faces that direction. Roblox's default controls already handle screen-relative movement in third-person, but we'll add a script to ensure the character always faces the direction it's moving. This makes it feel more like Brawl Stars.
Create another LocalScript in StarterPlayerScripts (or the same one as above). This script will:
Listen for input (e.g., WASD keys or arrow keys).
Calculate the movement direction based on the camera's orientation.
Move the character and make it face that direction.
Here's the code:
lua
-- LocalScript: CustomMovement.lua (can be in the same script as CustomCamera if you combine them)
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local moveVector = Vector3.new(0, 0, 0) -- Tracks the direction of movement
local walkSpeed = 16 -- Default walk speed; adjust as needed
-- Function to move the character
local function moveCharacter()
if humanoid and humanoidRootPart then
local camera = workspace.CurrentCamera
local moveDirection = (camera.CFrame * CFrame.new(moveVector)).Position - humanoidRootPart.Position
moveDirection = Vector3.new(moveDirection.X, 0, moveDirection.Z).unit -- Ignore Y-axis for ground movement
if moveDirection.Magnitude > 0 then
humanoid:MoveTo(humanoidRootPart.Position + moveDirection * walkSpeed)
humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position, humanoidRootPart.Position + moveDirection)
-- This makes the character face the direction it's moving
else
humanoid:MoveTo(humanoidRootPart.Position) -- Stop if no input
end
end
end
-- Listen for input
UserInputService.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
moveVector = Vector3.new(0, 0, 0) -- Reset vector
if UserInputService:IsKeyDown(Enum.KeyCode.W) then
moveVector = moveVector + Vector3.new(0, 0, -1) -- Forward
end
if UserInputService:IsKeyDown(Enum.KeyCode.S) then
moveVector = moveVector + Vector3.new(0, 0, 1) -- Backward
end
if UserInputService:IsKeyDown(Enum.KeyCode.A) then
moveVector = moveVector + Vector3.new(-1, 0, 0) -- Left
end
if UserInputService:IsKeyDown(Enum.KeyCode.D) then
moveVector = moveVector + Vector3.new(1, 0, 0) -- Right
end
moveVector = moveVector.unit -- Normalize the vector
end
end)
RunService.RenderStepped:Connect(moveCharacter) -- Update movement every frame
What this does:
It listens for keyboard input (WASD) and builds a movement vector based on the keys pressed.
The movement direction is transformed by the camera's CFrame, so it's screen-relative (e.g., W always moves toward the top of the screen as seen by the camera).
The character moves in that direction using Humanoid:MoveTo(), and we immediately rotate it to face the direction using HumanoidRootPart.CFrame.
This runs every frame to make movement smooth.
Notes on Movement:
This overrides the default Roblox movement, so the character will only respond to the inputs we define.
If you want to support controllers or mobile (e.g., thumbsticks), you'd need to expand the input handling in UserInputService.InputChanged to check for Enum.UserInputType.Gamepad1 or touch inputs.
The character will stop moving when no keys are pressed.
Potential Improvements and Tips
Shooting Mechanism: Since your game involves shooting, you'll probably want to add a separate system for that. For example, you could use another input (like mouse click or a key) to fire in the direction the character is facing. Let me know if you need help with that!
Mobile Support: Brawl Stars is mobile-first, so if you're targeting mobile players, consider adding on-screen joysticks. You can use Roblox's ContextActionService or a UI library for this.
Performance: Using RenderStepped for both camera and movement is fine for most games, but if you notice lag, you could optimize by combining the scripts into one.
Testing: Playtest in Roblox Studio. Make sure the camera feels right by adjusting the offsets and angles. Also, test movement on different devices to ensure it's responsive.
Edge Cases: If the character dies or respawns, the scripts might need to wait for the new character. You can add error handling, like reconnecting to player.CharacterAdded.
This should give you a solid Brawl Stars-like setup. If you run into issues or need to add features (like jumping, animations, or shooting), just let me know—I can refine this further! 🚀