mirror of
https://github.com/DrBeef/JKXR.git
synced 2024-11-21 19:51:33 +00:00
Academy-IRL-Crouch
This commit is contained in:
parent
ac8ac8f6d9
commit
5813c42b30
2 changed files with 81 additions and 0 deletions
|
@ -80,6 +80,12 @@ void CalcEntitySpot ( const gentity_t *ent, const spot_t spot, vec3_t point )
|
|||
if ( ent->client->NPC_class == CLASS_ATST )
|
||||
{//adjust up some
|
||||
point[2] += 28;//magic number :)
|
||||
} else if (!ent->client->ps.clientNum) {
|
||||
// When IRL crouch is used, view height is higher than model height
|
||||
// We need to lower "point" else enemies will be aiming into empty space
|
||||
int viewHeight = ent->client->ps.viewheight - STANDARD_VIEWHEIGHT_OFFSET;
|
||||
int realHeight = ent->maxs[2];
|
||||
point[2] -= viewHeight - realHeight;
|
||||
}
|
||||
if ( ent->NPC )
|
||||
{//always aim from the center of my bbox, so we don't wiggle when we lean forward or backwards
|
||||
|
@ -116,6 +122,12 @@ void CalcEntitySpot ( const gentity_t *ent, const spot_t spot, vec3_t point )
|
|||
if ( ent->client->NPC_class == CLASS_ATST )
|
||||
{//adjust up some
|
||||
point[2] += 28;//magic number :)
|
||||
} else if (!ent->client->ps.clientNum) {
|
||||
// When IRL crouch is used, view height is higher than model height
|
||||
// We need to lower "point" else enemies will be aiming into empty space
|
||||
int viewHeight = ent->client->ps.viewheight - STANDARD_VIEWHEIGHT_OFFSET;
|
||||
int realHeight = ent->maxs[2];
|
||||
point[2] -= viewHeight - realHeight;
|
||||
}
|
||||
if ( ent->NPC )
|
||||
{//always aim from the center of my bbox, so we don't wiggle when we lean forward or backwards
|
||||
|
|
|
@ -45,6 +45,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|||
#include "wp_saber.h"
|
||||
#include "g_vehicles.h"
|
||||
#include <float.h>
|
||||
#include <JKXR/VrClientInfo.h>
|
||||
|
||||
extern qboolean G_DoDismemberment( gentity_t *self, vec3_t point, int mod, int damage, int hitLoc, qboolean force = qfalse );
|
||||
extern qboolean G_EntIsUnlockedDoor( int entityNum );
|
||||
|
@ -5784,6 +5785,74 @@ static void PM_CheckDuck (void)
|
|||
pm->ps->pm_flags |= PMF_DUCKED;
|
||||
return;
|
||||
}
|
||||
|
||||
// IRL Crouch
|
||||
cvar_t *vr_irl_crouch_enabled = gi.cvar("vr_irl_crouch_enabled", "0", CVAR_ARCHIVE); // defined in VrCvars.h
|
||||
if (vr && !pm->ps->clientNum && vr_irl_crouch_enabled->integer && (!cg.renderingThirdPerson || vr_irl_crouch_enabled->integer > 1)) {
|
||||
// In-game view height always matches full stand height
|
||||
// (we are crouching IRL, no need to artificially lower view)
|
||||
pm->ps->viewheight = standheight + STANDARD_VIEWHEIGHT_OFFSET;
|
||||
|
||||
// Compute in-game height based on HMD height above floor
|
||||
// (adjust height only when crouching, ignore IRL jumps)
|
||||
int computedHeight = standheight;
|
||||
if (crouchheight < standheight && vr->curHeight < vr->maxHeight) {
|
||||
// Count minimum IRL crouch height based on maximum IRL height
|
||||
cvar_t *vr_irl_crouch_to_stand_ratio = gi.cvar("vr_irl_crouch_to_stand_ratio", "0.65", CVAR_ARCHIVE); // defined in VrCvars.h
|
||||
float minHeight = vr->maxHeight * vr_irl_crouch_to_stand_ratio->value;
|
||||
if (vr->curHeight < minHeight) { // Do not allow to crawl (set min height)
|
||||
computedHeight = crouchheight;
|
||||
} else {
|
||||
float heightRatio = (vr->curHeight - minHeight) / (vr->maxHeight - minHeight);
|
||||
computedHeight = crouchheight + (int)(heightRatio * (standheight - crouchheight));
|
||||
}
|
||||
}
|
||||
|
||||
// When in the air, move origin (we are lifting or dropping legs)
|
||||
bool liftingLegs = computedHeight < oldHeight;
|
||||
if (pm->ps->groundEntityNum == ENTITYNUM_NONE) {
|
||||
pm->ps->origin[2] += oldHeight - computedHeight;
|
||||
// Compensate view height
|
||||
pm->ps->viewheight -= oldHeight - computedHeight;
|
||||
}
|
||||
|
||||
// Adjust height based on where are you standing
|
||||
// (cannot stand up if there is no place, find nearest possible height)
|
||||
for (int i = computedHeight; i > 0; i--) {
|
||||
pm->maxs[2] = i;
|
||||
pm->trace( &trace, pm->ps->origin, pm->mins, pm->maxs, pm->ps->origin, pm->ps->clientNum, pm->tracemask, G2_NOCOLLIDE, 0 );
|
||||
if ( !trace.allsolid ) {
|
||||
break;
|
||||
} else if (pm->ps->groundEntityNum == ENTITYNUM_NONE) {
|
||||
// When in the air, adjust origin (we are lifting or dropping legs)
|
||||
if (liftingLegs) {
|
||||
pm->ps->origin[2]--;
|
||||
// Compensate view height
|
||||
pm->ps->viewheight++;
|
||||
} else {
|
||||
pm->ps->origin[2]++;
|
||||
// Compensate view height
|
||||
pm->ps->viewheight--;
|
||||
}
|
||||
} else {
|
||||
// Lower view height to not see through ceiling
|
||||
// (in case you stand up IRL in tight place)
|
||||
pm->ps->viewheight--;
|
||||
}
|
||||
}
|
||||
|
||||
// Toggle duck flag based on in-game height (need to be at least half-way crouched)
|
||||
if (pm->maxs[2] < crouchheight + (standheight - crouchheight)/2) {
|
||||
//Com_Printf( "CROUCHING: %.2f/%.2f -> %i ->%i\n", vr->curHeight, vr->maxHeight, computedHeight, (int) pm->maxs[2] );
|
||||
pm->ps->pm_flags |= PMF_DUCKED;
|
||||
} else {
|
||||
//Com_Printf( "STANDING: %.2f/%.2f -> %i -> %i\n", vr->curHeight, vr->maxHeight, computedHeight, (int) pm->maxs[2] );
|
||||
pm->ps->pm_flags &= ~PMF_DUCKED;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( pm->cmd.upmove < 0 )
|
||||
{ // trying to duck
|
||||
pm->maxs[2] = crouchheight;
|
||||
|
|
Loading…
Reference in a new issue