I'm trying to add the [B]viewDelta [/B]from CS:S for better air-crouching.
I'm using all the CS:S hulls with: SetHull, SetHullDuck, SetViewOffset, SetViewOffsetDucked
[url]https://developer.valvesoftware.com/wiki/Player_Entity[/url]
CS:S Crouch Code (Momentum BHOP Mod with CS:S Movement):
[CODE]void CMomentumGameMovement::Duck(void)
{
int buttonsChanged = (mv->m_nOldButtons ^ mv->m_nButtons); // These buttons have changed this frame
int buttonsPressed = buttonsChanged & mv->m_nButtons; // The changed ones still down are "pressed"
int buttonsReleased =
buttonsChanged & mv->m_nOldButtons; // The changed ones which were previously down are "released"
// Check to see if we are in the air.
bool bInAir = player->GetGroundEntity() == nullptr && player->GetMoveType() != MOVETYPE_LADDER;
if (mv->m_nButtons & IN_DUCK)
{
mv->m_nOldButtons |= IN_DUCK;
}
else
{
mv->m_nOldButtons &= ~IN_DUCK;
}
if (IsDead())
{
// Unduck
if (player->GetFlags() & FL_DUCKING)
{
FinishUnDuck();
}
return;
}
HandleDuckingSpeedCrop();
if (m_pPlayer->m_duckUntilOnGround)
{
if (!bInAir)
{
m_pPlayer->m_duckUntilOnGround = false;
if (CanUnduck())
{
FinishUnDuck();
}
return;
}
else
{
if (mv->m_vecVelocity.z > 0.0f)
return;
// Check if we can un-duck. We want to unduck if we have space for the standing hull, and
// if it is less than 2 inches off the ground.
trace_t trace;
Vector newOrigin;
Vector groundCheck;
VectorCopy(mv->GetAbsOrigin(), newOrigin);
Vector hullSizeNormal = VEC_HULL_MAX - VEC_HULL_MIN;
Vector hullSizeCrouch = VEC_DUCK_HULL_MAX - VEC_DUCK_HULL_MIN;
newOrigin -= (hullSizeNormal - hullSizeCrouch);
groundCheck = newOrigin;
groundCheck.z -= player->GetStepSize();
UTIL_TraceHull(newOrigin, groundCheck, VEC_HULL_MIN, VEC_HULL_MAX, PlayerSolidMask(), player,
COLLISION_GROUP_PLAYER_MOVEMENT, &trace);
if (trace.startsolid || trace.fraction == 1.0f)
return; // Can't even stand up, or there's no ground underneath us
m_pPlayer->m_duckUntilOnGround = false;
if (CanUnduck())
{
FinishUnDuck();
}
return;
}
}
// Holding duck, in process of ducking or fully ducked?
if ((mv->m_nButtons & IN_DUCK) || (player->m_Local.m_bDucking) || (player->GetFlags() & FL_DUCKING))
{
if (mv->m_nButtons & IN_DUCK)
{
bool alreadyDucked = (player->GetFlags() & FL_DUCKING) ? true : false;
if ((buttonsPressed & IN_DUCK) && !(player->GetFlags() & FL_DUCKING))
{
// Use 1 second so super long jump will work
player->m_Local.m_flDucktime = 1000;
player->m_Local.m_bDucking = true;
}
float duckmilliseconds = max(0.0f, 1000.0f - (float)player->m_Local.m_flDucktime);
float duckseconds = duckmilliseconds / 1000.0f;
// time = max( 0.0, ( 1.0 - (float)player->m_Local.m_flDucktime / 1000.0 ) );
if (player->m_Local.m_bDucking)
{
// Finish ducking immediately if duck time is over or not on ground
if ((duckseconds > TIME_TO_DUCK) || (player->GetGroundEntity() == nullptr) || alreadyDucked)
{
FinishDuck();
}
else
{
// Calc parametric time
float duckFraction = SimpleSpline(duckseconds / TIME_TO_DUCK);
SetDuckedEyeOffset(duckFraction);
}
}
}
else
{
// Try to unduck unless automovement is not allowed
// NOTE: When not onground, you can always unduck
if (player->m_Local.m_bAllowAutoMovement || player->GetGroundEntity() == nullptr)
{
if ((buttonsReleased & IN_DUCK) && (player->GetFlags() & FL_DUCKING))
{
// Use 1 second so super long jump will work
player->m_Local.m_flDucktime = 1000;
player->m_Local.m_bDucking = true; // or unducking
}
float duckmilliseconds = max(0.0f, 1000.0f - (float)player->m_Local.m_flDucktime);
float duckseconds = duckmilliseconds / 1000.0f;
if (CanUnduck())
{
if (player->m_Local.m_bDucking || player->m_Local.m_bDucked) // or unducking
{
// Finish ducking immediately if duck time is over or not on ground
if ((duckseconds > TIME_TO_UNDUCK) || (player->GetGroundEntity() == nullptr))
{
FinishUnDuck();
}
else
{
// Calc parametric time
float duckFraction = SimpleSpline(1.0f - (duckseconds / TIME_TO_UNDUCK));
SetDuckedEyeOffset(duckFraction);
}
}
}
else
{
// Still under something where we can't unduck, so make sure we reset this timer so
// that we'll unduck once we exit the tunnel, etc.
player->m_Local.m_flDucktime = 1000;
}
}
}
}
}
Stop ducking
void CMomentumGameMovement::FinishUnDuck(void)
{
trace_t trace;
Vector newOrigin;
VectorCopy(mv->GetAbsOrigin(), newOrigin);
if (player->GetGroundEntity() != nullptr)
{
newOrigin += VEC_DUCK_HULL_MIN - VEC_HULL_MIN;
}
else
{
// If in air an letting go of croush, make sure we can offset origin to make
// up for uncrouching
Vector hullSizeNormal = VEC_HULL_MAX - VEC_HULL_MIN;
Vector hullSizeCrouch = VEC_DUCK_HULL_MAX - VEC_DUCK_HULL_MIN;
Vector viewDelta = -0.5f * (hullSizeNormal - hullSizeCrouch);
VectorAdd(newOrigin, viewDelta, newOrigin);
}
player->m_Local.m_bDucked = false;
player->RemoveFlag(FL_DUCKING);
player->m_Local.m_bDucking = false;
player->SetViewOffset(GetPlayerViewOffset(false));
player->m_Local.m_flDucktime = 0.f;
mv->SetAbsOrigin(newOrigin);
// Recategorize position since ducking can change origin
CategorizePosition();
}
Finish ducking
void CMomentumGameMovement::FinishDuck(void)
{
Vector hullSizeNormal = VEC_HULL_MAX - VEC_HULL_MIN;
Vector hullSizeCrouch = VEC_DUCK_HULL_MAX - VEC_DUCK_HULL_MIN;
Vector viewDelta = 0.5f * (hullSizeNormal - hullSizeCrouch);
player->SetViewOffset(GetPlayerViewOffset(true));
player->AddFlag(FL_DUCKING);
player->m_Local.m_bDucking = false;
if (!player->m_Local.m_bDucked)
{
Vector org = mv->GetAbsOrigin();
if (player->GetGroundEntity() != nullptr)
{
org -= VEC_DUCK_HULL_MIN - VEC_HULL_MIN;
}
else
{
org += viewDelta;
}
mv->SetAbsOrigin(org);
player->m_Local.m_bDucked = true;
}
// See if we are stuck?
FixPlayerCrouchStuck(true);
// Recategorize position since ducking can change origin
CategorizePosition();
}[/CODE]
[CODE]hullSizeNormal = VEC_HULL_MAX - VEC_HULL_MIN
hullSizeCrouch = VEC_DUCK_HULL_MAX - VEC_DUCK_HULL_MIN
viewDelta = 0.5 * (hullSizeNormal - hullSizeCrouch)[/CODE]
How would I add that to the Z duck
You'd have to return true in the Move hook and remake the entire move system in this case.
[QUOTE=code_gs;52262732]You'd have to return true in the Move hook and remake the entire move system in this case.[/QUOTE]
So the only way to do this without coding a entrie move system is just by adding 53.5 instead of 45 because: 62 - 45 = 17 * 0.5 = 8.5 + 45
[CODE]SetHull( Vector( -16, -16, 0 ), Vector( 16, 16, 62 ) )
SetHullDuck( Vector(-16, -16, 0 ), Vector( 16, 16, 53.5) )[/CODE]
[QUOTE=FiBzY;52262773]So the only way to do this without coding a entrie move system is just by adding 53.5 instead of 45 because: 62 - 45 = 17 * 0.5 = 8.5 + 45
[CODE]SetHull( Vector( -16, -16, 0 ), Vector( 16, 16, 62 ) )
SetHullDuck( Vector(-16, -16, 0 ), Vector( 16, 16, 53.5) )[/CODE][/QUOTE]
That's just the conservative option for the hull; it won't always be correct but you should be able to fit under everything in CS:S maps.
[editline]22nd May 2017[/editline]
Also note that [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/SetViewOffset]Player:SetViewOffset[/url] is also a function that has a different value from CS:S.
[QUOTE=code_gs;52263225]That's just the conservative option for the hull; it won't always be correct but you should be able to fit under everything in CS:S maps.
[editline]22nd May 2017[/editline]
Also note that [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/SetViewOffset]Player:SetViewOffset[/url] is also a function that has a different value from CS:S.[/QUOTE]
Yea, because i'm using CS:S bunny Hop maps on the gamemode so i'm trying to get the movement as close as CS:S as possible. Even crouching because, it's important to make everything work with CS:S hulls...
I'm using SetViewOffset too
[CODE]PLAYER.gViewVectors = {
VEC_VIEW = Vector(0, 0, 62), // eye position
VEC_HULL_MIN = Vector(-16, -16, 0), // hull min
VEC_HULL_MAX = Vector(16, 16, 62), // hull max
VEC_HULL_COLLISON_MAX = Vector( 16, 16, 72), // hull max collison
VEC_HULL_COLLISON_MIN = Vector( -16, -16, 0 ), // hull min collison
VEC_DUCK_HULL_MIN = Vector(-16, -16, 0), // duck hull min
VEC_DUCK_HULL_MAX = Vector(16, 16, 45), // duck hull max - add viewdelta
VEC_DUCK_VIEW = Vector( 0, 0, 45) // duck view
}
function Player:SetupHull()
self:SetHull( PLAYER.gViewVectors.VEC_HULL_MIN, PLAYER.gViewVectors.VEC_HULL_MAX )
self:SetHullDuck( PLAYER.gViewVectors.VEC_DUCK_HULL_MIN, PLAYER.gViewVectors.VEC_DUCK_HULL_MAX)
self:SetCollisionBounds( PLAYER.gViewVectors.VEC_HULL_COLLISON_MIN, PLAYER.gViewVectors.VEC_HULL_COLLISON_MAX)
self:SetViewOffset( PLAYER.gViewVectors.VEC_VIEW )
self:SetViewOffsetDucked( PLAYER.gViewVectors.VEC_DUCK_VIEW )
self:SetModelScale( 1, 0 )
if (SERVER) then
net.Start( "SetupHull" )
net.WriteEntity( self )
net.Broadcast()
end
end[/CODE]
bump
I don't know what else you're asking. GMod uses the default/HL2DM crouching movement code; you're not going to get the same results without rewriting it.
Sorry, you need to Log In to post a reply to this thread.