ZQFMGB12Join Date: 2010-08-07 Post Count: 208 |
I need a method or algorithm to check if a player is grounded. A player is grounded when there is a solid part beneath the player's feet.
I know that there is an event that belongs to Humanoid that fires (Enum.HumanoidStateType.Landed) when the player is lands, but I feel that the event is inaccurate.
For example, if a player spin jumps (custom scripted action) and there is a part right on top of the player, the grounded event won't fire and the script won't work. This is because in the script, a spin jump has a debounce variable and it becomes false when the player is grounded.
Does anybody have any ideas? |
|
128GBJoin Date: 2014-04-17 Post Count: 8056 |
ray casting |
|
|
ZQFMGB12Join Date: 2010-08-07 Post Count: 208 |
elaborate please? |
|
TynexxJoin Date: 2012-07-11 Post Count: 1559 |
And/Or maybe magnitude |
|
128GBJoin Date: 2014-04-17 Post Count: 8056 |
'And/Or maybe magnitude'
yes loop through every single item in the game instead of sending a line to see if there is anything 2.5 blocks below the torso other than the legs
what could go wrong |
|
ZQFMGB12Join Date: 2010-08-07 Post Count: 208 |
Will ray casting work even though the part is rotated in any of the three axes? |
|
128GBJoin Date: 2014-04-17 Post Count: 8056 |
It'll work as long as you check if something is below the feet
It won't matter what it is or how its rotated as long as you check directly below the feet
Would probably want to make it check if said brick is cancollide = true though |
|
|
|
char.Humanoid.Changed:connect(function()
if char.Humanoid.Jump.Value == true then
repeat wait() until char.Torso.Velocity.Y == 0
print'Ground'
end
end)
I tested it and it works fine, it has about a second delay though. |
|
|
char.Humanoid.Changed:connect(function()
if char.Humanoid.Jump == true then
repeat wait() until char.Torso.Velocity.Y == 0
print'Ground'
end
end) |
|
ZQFMGB12Join Date: 2010-08-07 Post Count: 208 |
That won't work because not all extra movements I'm including make Humanoid.Jump become true. |
|
|
So long as they do not fall over, you can just use the ray:
Ray.new(torso.Position, Vector3.new(0, -3.05, 0))
and it will return if they are grounded (Most of the time) (Will not work if they are not fully on a part) (Will not work if they are standing on something with lots of small holes in it) |
|
ZQFMGB12Join Date: 2010-08-07 Post Count: 208 |
I don't plan to be too evil with platform placing yet (0.2x0.2x0.2 stud platforms) because of the new awkward traction physics on Roblox |
|
|
You can also make the entire collidable world invisible and make the fancy visual stuff non-collide (Or use CSGs when they eventually appear) :P |
|
128GBJoin Date: 2014-04-17 Post Count: 8056 |
@Not
0.2 x 0.2 x 0.2 blocks set to cancollide = false still bug your character out when you touch them sometimes |
|
|
@128GB: Oh, yeah. I forgot this was ROBLOX. |
|
ZQFMGB12Join Date: 2010-08-07 Post Count: 208 |
Raycasting works beautifully...for now!
Wasted 120 robux trying to fix some animations before ray casting.
|
|
blockooJoin Date: 2007-11-08 Post Count: 17202 |
If I were to do this, I would do something with the "FreeFalling" and "Running" events of the Humanoid. |
|
|
ZQFMGB12Join Date: 2010-08-07 Post Count: 208 |
@blockhoo
Been there, done that, the enums aren't very accurate for what I'm trying to accomplish. For example, when you spin jump, my movement script sets a variable to false and when you touch the ground, it becomes true. Say you spin jump right under a part. If I used Enums, the events wouldn't fire because the player appears to have not jumped, but the variable is still set to false (which disallows jumping).
I think ray casting for now is the superior option. |
|