I’ve actually had a similar project to yours. Feel free to mess around with my camera code below:
local middle = (hRPPosition + hRP2Position)/2
local distance = (hRPPosition - hRP2Position).Magnitude
if distance < 15 then
distance = 15
end
camera.CFrame = CFrame.new(Vector3.new(middle.X, middle.Y, middle.Z - distance), middle)
camera.FieldOfView = 70 - distance/1.5
(RenderStepped loop)
If you need to have just Player’s position, no need to get Root part as Origin position exists there.
magnitude it’s for zooming, right?
I have the same code you have, without “distance/1.5”. Why did you put that?
btw, It looks really nice
The number I divide the distance by is just a sweetspot I’ve found so it fits within my map dimensions. Too big and the camera goes past the walls and starts to warp resulting in the loss of the 2d effect.
(Let me know if you have any other issues/questions cause I’ve most likely gone through everything you have currently.)
you know how to resolve my issue that I have on this post?
find hrp of two different players on a server
On a reply there is a solution button you can click.
Oops, I miss interpreted your comment sorry. Yeah one second lemme give a read through that issue too.
The reason why position
was nil due to the character either not being loaded in time or respawned. Assuming you only have two players and constantly want to update that you can do it like so:
--some multiple methods of getting the root part
--get root part via connect
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoidRootPart = character.HumanoidRootPart
end)
end)
--get root part from player
local character = player.Character or player.CharacterAdded:Wait() --this waits for the character to load
local humanoidRootPart = character.HumanoidRootPart
--use whatever method to just update a root1 and root2 variables
Editing/using your current code:
local roots = {}
for i, v in pairs(game.Players:GetPlayers()) do
local character = v.Character or v.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
table.insert(roots, humanoidRootPart)
end
print(roots) --this will just return empty though as the players havent joined yet.
Overall I recommend you rely on .CharacterAdded to update pre-existing variables.
You don’t necessarily have to use HumanoidRootPart though that is the center of the character and most reliable. If you want to use the heads of the character than go ahead. I’ve given a example below.
--there is most likely a better way to handle this but here
local heads = {}
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local head = character:WaitForChild("Head") --get character head
if heads[1] then --check if heads are already pre-existing
if heads[1][2] == player.Name then --check if they are player1
heads[1][1] = head --if player1 then update player1
else
heads[2][1] = head --if player2 then update player2
end
else
table.insert(heads, {head, player.Name}) --if not then add new head to array
end
end)
end)
Print (rootParts) for me, we’ll be able to see exactly how to reference it.
Don’t put your RenderStepped loop inside the .CharacterAdded() cause otherwise it will execute it twice due to each character load. Move it outside and and a check to see if the heads table isn’t empty/exists.
Also why are you handling the camera on the server? It’s going to feel sluggish and slow under real environments as the clients character to the server will always be different.
Your printing heads way before the player even joins the game… You can see by simply adding a wait.
local example = {}
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
table.insert(example, player.Name)
end)
end)
print(example) --{}
task.wait(5)
print(example) --{alphajpeg}
I sent you the exact code you need way earlier for the client side. Refer to that if you want it to work.
It works? It show me this:
(btw try to have patience with me 'cause i’m still a begginer at this roblox studio scripting stuff )
Yes it works? I’m confused what your issue is here now.
It’s nothing, it works fine. The only issue for me it’s trying to connect client with server
Can you please mark someone’s solution then, server to client stuff could be for a different question if you need help.
Ok! Thanks for helping me, I appreciate it so much!!