Skip to content

Commit

Permalink
wip Explicit dismount for ladders near the top
Browse files Browse the repository at this point in the history
  • Loading branch information
fholger committed Aug 27, 2023
1 parent 0189d4b commit 70ae7f4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Sources/CryGame C++/Solution1/CryGame/ScriptObjectPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2290,6 +2290,9 @@ int CScriptObjectPlayer::UseLadder(IFunctionHandler *pH)
if(onLadder!=0 && !m_pPlayer->m_stats.onLadder)
{
m_pPlayer->m_insideLadderVolume = true;
m_pPlayer->m_activeHandGrabbingLadder = false;
m_pPlayer->m_wasGrabbingLadder[0] = false;
m_pPlayer->m_wasGrabbingLadder[1] = false;
m_pPlayer->m_PrevWeaponID=m_pPlayer->GetSelectedWeaponId();
m_pPlayer->SelectWeapon(-1);
m_pPlayer->m_stats.onLadder = true;
Expand Down
33 changes: 30 additions & 3 deletions Sources/CryGame C++/Solution1/CryGame/XPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1919,15 +1919,18 @@ void CPlayer::ProcessMovements(CXEntityProcessingCmd &cmd, bool bScheduled)
if (speedxyz[2] > 0)
{
// add a bit of forward movement for dismounts at the top
speedxyz[0] = -m_psin * 0.50f;
speedxyz[1] = m_pcos * 0.50f;
//speedxyz[0] = -m_psin * 0.50f;
//speedxyz[1] = m_pcos * 0.50f;
}
m_prevLadderGrabPos = curGrabPos;
}
m_wasGrabbingLadder[i] = grabbing[i];
}
if (!grabbing[0] && !grabbing[1])
if (m_activeHandGrabbingLadder != -1 && !grabbing[m_activeHandGrabbingLadder])
{
m_activeHandGrabbingLadder = -1;
CheckLadderDismount();
}

if (m_activeHandGrabbingLadder == -1 && !m_insideLadderVolume)
{
Expand Down Expand Up @@ -7095,6 +7098,30 @@ void CPlayer::CheckMeleeWeaponSwing()
m_prevHandPos = handPos;
}

void CPlayer::CheckLadderDismount()
{
Matrix34 cameraTransform = Matrix34::CreateRotationXYZ(Deg2Rad(m_pEntity->GetCamera()->GetAngles()), m_pEntity->GetCamera()->GetPos());
Vec3 fwd = cameraTransform.GetForward();
fwd.z = 0;
fwd.Normalize();
Vec3 testPos = cameraTransform.GetTranslation() + fwd * 1.0f + Vec3(0, 0, 0.5f);

// find floor
IPhysicalWorld* world = m_pGame->GetSystem()->GetIPhysicalWorld();
int objTypes = ent_terrain|ent_static;
int flags = rwi_stop_at_pierceable|rwi_ignore_terrain_holes;
ray_hit hit;
int col = world->RayWorldIntersection(testPos, Vec3(0, 0, -2), objTypes, flags, &hit, 1, m_pEntity->GetPhysics());
if (col)
{
Vec3 dismountCandidate = hit.pt;
if (CanStand(dismountCandidate))
{
m_pEntity->SetPos(dismountCandidate);
}
}
}

//////////////////////////////////////////////////////////////////////
void CPlayer::OnEntityNetworkUpdate( const EntityId &idViewerEntity, const Vec3d &v3dViewer, uint32 &inoutPriority,
EntityCloneState &inoutCloneState) const
Expand Down
2 changes: 2 additions & 0 deletions Sources/CryGame C++/Solution1/CryGame/XPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,8 @@ enum eInVehiclestate
int m_activeHandGrabbingLadder = -1;
Vec3 m_prevLadderGrabPos;
bool m_insideLadderVolume = false;

void CheckLadderDismount();
};

#endif // __GAME_PLAYER_H__

0 comments on commit 70ae7f4

Please sign in to comment.