@@ -188,7 +188,7 @@ ActionResult<CNEOBot> CNEOBotLadderClimb::Update( CNEOBot *me, float /*interval*
188188 }
189189
190190 // Check if we're on the ladder (MOVETYPE_LADDER or locomotion says so)
191- bool onLadder = me->IsOnLadder ();
191+ bool onLadder = me->IsBotOnLadder ();
192192
193193 if ( !onLadder )
194194 {
@@ -201,7 +201,7 @@ ActionResult<CNEOBot> CNEOBotLadderClimb::Update( CNEOBot *me, float /*interval*
201201 {
202202 Vector ladderClosestPoint;
203203 CalcClosestPointOnLineSegment ( myPos, m_ladder->m_bottom , m_ladder->m_top , ladderClosestPoint );
204- if ( myPos.DistToSqr ( ladderClosestPoint ) > Square ( 100 . 0f ) )
204+ if ( myPos.DistToSqr ( ladderClosestPoint ) > Square ( MAX_DEVIATION_DIST ) )
205205 {
206206 return Done ( " Fallen too far from ladder, resetting" );
207207 }
@@ -227,6 +227,7 @@ ActionResult<CNEOBot> CNEOBotLadderClimb::Update( CNEOBot *me, float /*interval*
227227 if ( distToTarget < mover->GetStepHeight () * 2 .0f )
228228 {
229229 EnterDismountPhase ( me );
230+ return Continue ();
230231 }
231232 else
232233 {
@@ -260,96 +261,60 @@ ActionResult<CNEOBot> CNEOBotLadderClimb::Update( CNEOBot *me, float /*interval*
260261 if ( m_bGoingUp )
261262 {
262263 body->SetDesiredPosture ( IBody::STAND );
264+ }
263265
264- float dismountZ = targetZ;
265-
266- if ( m_pExitArea && bExitIsBehind )
267- {
268- dismountZ = MIN ( m_exitAreaCenter.z , targetZ );
269- }
270-
271- if ( currentZ >= dismountZ )
272- {
273- EnterDismountPhase ( me );
274- return Continue ();
275- }
276-
277- bool bIsClimbingDown = false ;
278- if ( m_pExitArea )
266+ float dismountZ = targetZ;
267+ if ( m_pExitArea )
268+ {
269+ if ( m_bGoingUp )
279270 {
280- if ( currentZ < m_exitAreaCenter.z )
281- {
282- me->PressMoveUpButton ();
283- }
284- else
271+ if ( bExitIsBehind )
285272 {
286- me->PressMoveDownButton ();
287- bIsClimbingDown = true ;
273+ dismountZ = Min ( m_exitAreaCenter.z , targetZ );
288274 }
289275 }
290276 else
291277 {
292- me->PressMoveUpButton ();
293- }
294-
295- if ( !bIsClimbingDown )
296- {
297- me->PressForwardButton ();
278+ // Allow early drop-off at intermediate floors
279+ dismountZ = Max ( m_exitAreaCenter.z , targetZ );
298280 }
299-
300- // Look at the dismount height, slightly behind the ladder
301- Vector lookTarget = m_ladder->GetPosAtHeight ( dismountZ );
302- lookTarget -= m_ladder->GetNormal () * 50 .0f ;
303- body->AimHeadTowards ( lookTarget, IBody::MANDATORY, 0 .1f , nullptr , " Climbing up (looking at dismount position)" );
304281 }
305- else
282+
283+ // Check if we've reached the target exit height
284+ if ( m_bGoingUp ? ( currentZ >= dismountZ ) : ( currentZ <= dismountZ ) )
306285 {
307- float dismountZ = targetZ;
286+ EnterDismountPhase ( me );
287+ return Continue ();
288+ }
308289
290+ // Adjust vertical height based on target exit area
291+ bool bIsClimbingDown = false ;
292+ if ( onLadder )
293+ {
294+ bool bShouldGoUp = m_bGoingUp;
309295 if ( m_pExitArea )
310296 {
311- // Allow early drop-off at intermediate floors
312- dismountZ = MAX ( m_exitAreaCenter.z , targetZ );
313- }
314-
315- // Check if we've reached the bottom or intermediate exit height
316- if ( currentZ <= dismountZ )
317- {
318- EnterDismountPhase ( me );
319- return Continue ();
297+ bShouldGoUp = ( currentZ < m_exitAreaCenter.z );
320298 }
321299
322- // Adjust vertical height based on target exit area
323- bool bIsClimbingDown = false ;
324- if ( m_pExitArea && onLadder )
300+ if ( bShouldGoUp )
325301 {
326- if ( currentZ < m_exitAreaCenter.z )
327- {
328- me->PressMoveUpButton ();
329- }
330- else
331- {
332- me->PressMoveDownButton ();
333- bIsClimbingDown = true ;
334- }
302+ me->PressMoveUpButton ();
335303 }
336- else if ( onLadder )
304+ else
337305 {
338306 me->PressMoveDownButton ();
339307 bIsClimbingDown = true ;
340308 }
309+ }
341310
342- // Sanity check: don't press forward if we are actively climbing down
343- if ( !bIsClimbingDown )
344- {
345- me->PressForwardButton ();
346- }
347311
348- // Look at the dismount height, slightly behind the ladder
349- Vector lookTarget = m_ladder->GetPosAtHeight ( dismountZ );
350- lookTarget -= m_ladder->GetNormal () * 50 .0f ;
351- body->AimHeadTowards ( lookTarget, IBody::MANDATORY, 0 .1f , nullptr , " Climbing down (looking at dismount position)" );
352- }
312+ // Look at and move to the dismount height, slightly behind the ladder
313+ Vector lookTarget = m_ladder->GetPosAtHeight ( dismountZ );
314+ lookTarget -= m_ladder->GetNormal () * 50 .0f ;
315+ body->AimHeadTowards ( lookTarget, IBody::MANDATORY, 0 .1f , nullptr ,
316+ m_bGoingUp ? " Climbing up (looking at dismount position)" : " Climbing down (looking at dismount position)" );
317+ me->PressForwardButton (0 .1f );
353318 }
354319
355320 // ------------------------------------------------------------
@@ -372,9 +337,7 @@ ActionResult<CNEOBot> CNEOBotLadderClimb::Update( CNEOBot *me, float /*interval*
372337 // Build look target toward exit area center with vertical bias preserved
373338 if ( m_pExitArea )
374339 {
375- Vector dir = m_exitAreaCenter - myPos;
376- Vector lookTarget = myPos + dir;
377-
340+ bool bDroppingEarly = ( myPos.z >= m_exitAreaCenter.z );
378341 // Maintain Z-height while on the ladder in the dismount phase
379342 if ( onLadder )
380343 {
@@ -387,12 +350,15 @@ ActionResult<CNEOBot> CNEOBotLadderClimb::Update( CNEOBot *me, float /*interval*
387350 me->PressMoveDownButton ();
388351 }
389352 }
353+ else
354+ {
355+ bDroppingEarly = true ;
356+ }
390357
391- body->AimHeadTowards ( lookTarget , IBody::MANDATORY, 0 .1f , nullptr , " Walking to exit area" );
358+ body->AimHeadTowards ( m_exitAreaCenter , IBody::MANDATORY, 0 .1f , nullptr , " Walking to exit area" );
392359
393360 // Jump to detach from ladder if exit is not straight ahead, or if we have reached the exit height
394361 float dot = DotProduct ( toExit, m_ladderForward );
395- bool bDroppingEarly = ( myPos.z >= m_exitAreaCenter.z );
396362
397363 if ( dot < 0 .5f || bDroppingEarly )
398364 {
@@ -401,14 +367,10 @@ ActionResult<CNEOBot> CNEOBotLadderClimb::Update( CNEOBot *me, float /*interval*
401367 {
402368 me->PressJumpButton (); // mostly to trigger animation if possible
403369
404- // Zero Z velocity to avoid additive momentum from climbing, reducing overshoots
405- Vector currentVel = me->GetAbsVelocity ();
406- currentVel.z = 0 .0f ;
407370 mover->Reset (); // clear velocity cache in locomotion interface
408- me->SetAbsVelocity ( currentVel );
409371
410372 Vector jumpVelocity = toExit * 150 .0f ;
411- jumpVelocity.z = 150 .0f ;
373+ jumpVelocity.z = 150 .0f - me-> GetAbsVelocity (). z ;
412374
413375 me->ApplyAbsVelocityImpulse ( jumpVelocity );
414376 m_bJumpedOffLadder = true ;
@@ -450,10 +412,6 @@ ActionResult<CNEOBot> CNEOBotLadderClimb::Update( CNEOBot *me, float /*interval*
450412// ---------------------------------------------------------------------------------------------
451413void CNEOBotLadderClimb::EnterDismountPhase ( CNEOBot *me )
452414{
453- me->ReleaseMoveUpButton ();
454- me->ReleaseMoveDownButton ();
455- me->ReleaseForwardButton ();
456- me->GetLocomotionInterface ()->Reset (); // clear velocity cache in locomotion interface
457415 me->SetAbsVelocity ( vec3_origin ); // stop momentum
458416 m_bDismountPhase = true ;
459417 m_dismountTimer.Start ( DISMOUNT_TIMEOUT );
0 commit comments