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

How to find/change character distance from the ground? [Solved]

Asked by 7 years ago
Edited 7 years ago

I recently learned that character legs can collide, so what is it exactly determining how far a player model is from the ground, and how can I access this property? I found this out after disproportionately scaling player models, and I found that the legs were floating from the ground.

2 answers

Log in to vote
0
Answered by 7 years ago

Hip Height

Ad
Log in to vote
0
Answered by 7 years ago

Well to change it might be hard but here is how to detect how far it is from it, so first we are gonna be using Magnitude, magnitude is a term used across mathematics that means several things. In vector theory, the magnitude of a vector is the length of a vector, im not gonna go into depth on how it works, you want to learn more about it go here. So to get the magnitude between 2 parts you have to do

part1 = game.Workspace.Part1
part2 = game.Workspace.Part2

local Magnitude = (part1 - part2).magnitude
print(Magnitude)

but to always get it you can use a While Loop, to do so you want to add this small line of code

part1 = game.Workspace.Part1
part2 = game.Workspace.Part2

while wait() do
local Magnitude = (part1 - part2).magnitude
print(Magnitude)
end

so now that you know about how to get magnitude we can get the players distance between them, so this line of code should detect it

game.Players.PlayerAdded:connect(function(player)
    local character = player.Character or player.CharacterAdded:Wait()
    local ground = game.Workspace.Baseplate
while wait() do 
     if character then
        local torso = character.Torso
         if torso then
            local Magnitude = (torso.Position - ground.Position).magnitude
            if Magnitude > 172 then 
                print("Player is off of the ground")
                print(Magnitude)
            end
        end
    end
end 
end)

I hope this helped you!

0
Wow thanks! I don't have the rep to upvote but when I do I'll come back to upvote this. Toxicator1 4 — 7y

Answer this question