Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a player "flattened?"

Asked by 6 years ago

So I have this hammer weapon (a giant hammer thing) and when the user smashes another player, I want them to look flattened on the ground for a few seconds (they look like flat Stanley on the ground). I already have an animation that makes the victim lay on the ground, but any help on making a character appear flat/thin would be much appreciated.

0
You can always make an invisible part with the players decal on it so it looks flattened. greatneil80 2647 — 6y
0
I will be back with a sound solution in a little while. I've been working on it for an hour now. Just a bit more work and it will be done and pretty good if you ask me. I can show you it through a gif later. KingLoneCat 2642 — 6y
0
But, my solution will only work with R15 players, I haven't thought about R6 yet. KingLoneCat 2642 — 6y

3 answers

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

Hi tygerrupercut3,

I've been working on this flattened thing for the past hour trying to work the numbers right and get the coordinates right. So, I finally came to a good-enough solution. I mean.... a pretty good solution if you ask me, considering how easy it is. Well, I basically make use of the values inside of the Humanoid called: BodyHeightScale and HeadScale so that I can resize their avatars with ease. Then when I rescale them to a flat character, I make the head point up so that it looks like the character has been flattened.

After this, I anchor all of the parts and remove all the accessories that the character has. Well, I make the accessories transparent so that I can restore them with ease. Anyway, that's how I did it, let's just get into the script. Just know that this script isn't accustomed to your game, it's just something I made to show you a way you can accomplish your task.

Local Script inside StarterGui

local uis = game:GetService("UserInputService"); -- UserInputService for key input detection and stuff.
local players = game:GetService("Players");
local player = players.LocalPlayer;
local flattened = false; -- I use this as a way to decide if the character needs to be flat or come back to normal size. Once the character clicks, this sets to a certain value and I have the function check for that value and if it's that value, that means the character's flat and needs to come back to normal size, so I do that.

uis.InputBegan:Connect(function(key, gp) 
    if key.KeyCode == Enum.KeyCode.Q and not gp then
        local char = player.Character or player.CharacterAdded:Wait();
        local hum = char:WaitForChild("Humanoid");
        local head = char:WaitForChild("Head");
        local neck = head:WaitForChild("Neck"); -- The Motor6D, I need this to make the head point up.
        local height = hum:WaitForChild("BodyHeightScale"); 
        local torso = char:FindFirstChild("HumanoidRootPart");
        local anchoring = false -- I use this to decide if the parts should be anchored or not. They need to be anchored when the character gets flattened otherwise, they need to be unanchored. The reason I anchor them is to avoid the glitches with the physics in the game. 

        local anims = char:WaitForChild("Animate"); -- To stop the animations because those can get annoying. 

        if not flattened then -- If the character isn't flattened then this will pass.
            height.Value = 0; -- Sets the height to 0 s the character's body from torso down becomes flat. 
            anims.Disabled = true; -- Disables animations
            neck.C0 = CFrame.new(0, .03, -.3) * CFrame.Angles(math.rad(90), 0, 0); -- Makes the head point up.
            anchoring = true; -- Sets anchoring to true since we need to anchor the body parts.
        else -- Runs if flattened is true, meaning that the character is flattened.
            height.Value = 1;  -- Sets height back to normal.
            neck.C0 = CFrame.new(-5.96046448e-08, 0.839999914, 1.1920929e-07) * CFrame.Angles(math.rad(0), 0, 0); -- Makes the head point straight.
            anchoring = false; -- Sets anchoring to false.
        end


        wait(.15) -- Wait to make the body parts go a bit lower to the ground before anchoring them so that it looks like he/she got crushed.


        for _, obj in next, char:GetChildren() do -- For each iteration to go through each object in the character.
            if obj:IsA("BasePart") then -- If the object is a part that is connected to my body, this will pass.
                obj.Anchored = anchoring; -- Makes the object either anchored or unanchored depending on what anchoring was set to.
            elseif obj:IsA("Accessory") then -- If the object is an accessory, this will pass.
                local handle = obj:FindFirstChild("Handle"); -- Finds the handle, if there is one.
                if handle then -- Checks if there is a handle.
                    if anchoring then -- Checks if anchoring is true to decide if you need the accessories invisible or visible.
                        handle.Transparency = 1; -- Makes the accessory invisible
                    else -- Passes if anchoring is false.
                        handle.Transparency = 0;  -- Makes the accessory visible.
                    end -- end for if statement for checking if it's anchoring or not.
                end -- end for if statement to check if the accessory has a handle.
            end -- end for if statement checking if the object is a basepart, a part of my body.
        end -- end for for each iteration.

        anims.Disabled = false; Enables animations because, it doesn't matter at this point. The character is either anchored or just not flattened.

        flattened = not flattened; -- Makes flattened the opposite of what it is so next time it does the opposite affect. Meaning you just either got flattened or resized, so we need to do the opposite next time you run this function.
    end -- end for the first if statement
end) -- end for the function.

Well, this is the basic gist of it. You can find this in use here.

I hope I helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

0
The script isn't that big. Just lots of comments. KingLoneCat 2642 — 6y
0
Necrobump, beautiful code, accepted answer for you since tyger said it worked greatneil80 2647 — 3y
Ad
Log in to vote
0
Answered by
zyrun 168
6 years ago
Edited 6 years ago

This may not be the answer you're looking for, but I don't think there is a way... In your case, I would use One of Two ways:

1) Make a model of the flattened character, but not actually flatten them. Make parts and customize them with the player's colors and whatnot. Be sure to make the actual player's model invisible.

2) Anchor the character and CFrame them through the ground face up/down. This would look something like this:

-- In a sever script
function AnchorAllParts(InputArea) -- Will make sure anything that can be anchored will be anchored
    for _, V in pairs(InputArea:GetChildren()) do
        if V:IsA("BasePart") or V:IsA("UnionOperation") or V:IsA("MeshPart") then
            V.Anchored = true
        end
        if #V:GetChildren() > 0 then
            AnchorAllParts(V)
        end 
    end
end

-- Do your smashy stuff In this area here. Make sure you get the Player's Character HuamnoidRootPart as a varible so we can CFrame it

local CharRootPart = Plr.Character.HumanoidRootPart -- The HumanoidRootPart of the character


CharRootPart.CFrame = CharRootPart.CFrame * CFrame.Angles(math.pi/2, 0, 0) -- This will turn the player face up. Throw a Negative sign (-) right before math.pi inside of the paranthesis if you want the player face down
--Important Note: This will not make the character inside the ground, this should be enough to get you by though :)

AnchorAllParts(CharRootPart.Parent)

--Make sure there is no wait between the anchor and your CFraming (including putting them in the ground) or things could go wrong!

Hope this helped! - Zyrun

0
There is always a way! When there's a will, there's a way. KingLoneCat 2642 — 6y
Log in to vote
0
Answered by 6 years ago

I tried your script, and got it to work with a little tweaking to my needs. Thank you for taking time to make a nice script like that.

Answer this question