• Get the position of the floor?
    5 replies, posted
I'm not sure where to start. How can I get the vector of the floor below my player?
[lua]if ( Player:OnGround( ) ) then return Player:GetPos( ).z; else // do a trace straight down, and if it hits the world, return that position. end[/lua] The thing about player position, is that the actual player position is actually at their feet; the bottom of the model.
Oh, I want the position of the floor even if I'm in the air. I'm not sure how to trace downwards.
Do a trace down using util.TraceLine as mentioned in the commend in the code.
I see, I need to trace downward and add a mask for HitWorld.
Then it would be the else condition of the statement, also remove the .z if you want the entire location instead of just the z. for the else, just do a trace straight down Something like this: [lua] local _p = LocalPlayer( ); // Player var, change to what you need it to be // Trace Data local _td = { start = _p:GetPos( ); // Get player feet location endpos = _p:GetPos( ) + ( _p:GetAngles( ):Up( ) * -50000 ); // Trace down up to 50,000 units from feet -- filter = _p; // Don't stop tracing just because it hits the player - you may need to filter everything except world, whereby it may be simpler to use mask = Entity( 0 ) or game.GetWorld( ) mask = game.GetWorld( ) || Entity( 0 ); }; // Trace Line - execute a trace with the above data local _tr = util.TraceLine( _td ); // If the trace managed to find the world with a trace going straight down, then print it out if ( _tr.HitWorld ) then print( "World under feet at: " ); PrintTable( _tr.HitPos ); end[/lua]
Sorry, you need to Log In to post a reply to this thread.