Ad
Log in to vote
1

Camera Manipulation [closed]

Asked by 7 years ago

I want to manipulate a camera to be a "death cam", so that it watches the killer after a player dies. To be more descriptive, when the localplayer dies, the camera would zoom in on the player that killed them and then return to looking at the localplayer when they respawned. An example of this can be found in Litozinnamon's "Call of Robloxia 5". How would I be able to accomplish this task?

Locked by FearMeIAmLag

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
3
Answered by
MrNicNac 855 Moderation Voter
7 years ago

It's typical for a dying Humanoid to have one, or multiple, ObjectValues called 'creator' in them when they die. This is the standard for deaths/kills in ROBLOX (handling them, at least). So that could easily solve your "finding the killer" step.

Next, you could, for every time CharacterAdded fires, insert a LocalScript into the character that detects when the humanoid dies. Here's ax example of how it would work.

local cam = Workspace.CurrentCamera ;
local human = script.Parent:WaitForChild("Humanoid");

human.Died:connect(function()
    local creator = human:FindFirstChild("creator");
    if creator then
        if creator.Value then
            if creator.Value.Character then
                cam.CameraSubject = creator.Value.Character
                cam.CameraType = "Follow"
            end
        end
    end
end)
0
Setting the subject to the creator I see? that's not helpful Everesty 1001 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

In order to do this you're going to need to store some kind of data that tells the game who killed someone. You can achieve this by using an ObjectValue. In the weapons, you'll want to place a script that, when they attack someone, places an ObjectValue with the value set to their player/character.

This will need to be removed after a period of time otherwise you'd have multiple 'creator' values!

This can be achieved with the function game:GetService("Debris"):AddItem(item,duration), which removes an item after the specified duration.

Then, you'll want to connect an event to Humanoid.Died. This connection will need be handled on a LocalScript, as you want to control the user's camera.

Example:

local Character = game.Players.LocalPlayer.Character -- Retrieve their character...
local Camera = workspace.CurrentCamera - And then retrieve the camera, we'll be needing this shortly.

Character.Humanoid.Died:connect(function()
    local creator = Character.Humanoid:FindFirstChild("creator")
    if not creator then return end -- If we can't find out who killed them, we'll need to exit the function.
    local plyr = creator.Value
        if plyr and plyr.Character then -- If the player who killed them still exists...
        Camera.CameraType = "Follow" -- Set the CameraType to Follow, so it follows them.
        Camera.CameraSubject = plyr.Character -- Set the subject of the camera to their character.
        -- Display some kind of cool GUI here!
    end
end)