@@ -231,6 +231,7 @@ void Pedestrian::SimulationStep()
231231 ReceiveDamage (damageInfo);
232232 }
233233
234+ UpdateRotation ();
234235 UpdateLocomotion ();
235236}
236237
@@ -269,8 +270,7 @@ void Pedestrian::UpdateDrawOrder()
269270
270271void Pedestrian::UpdateLocomotion ()
271272{
272- if (mPhysicsBody == nullptr )
273- return ;
273+ debug_assert (mPhysicsBody );
274274
275275 float walkingSpeed = 0 .0f ;
276276
@@ -325,6 +325,48 @@ void Pedestrian::UpdateLocomotion()
325325 mPhysicsBody ->SetLinearVelocity (desiredVelocity);
326326}
327327
328+ void Pedestrian::UpdateRotation ()
329+ {
330+ cxx::angle_t angularVelocity;
331+
332+ bool isSlideOverCar = (ePedestrianState_SlideOnCar == GetCurrentStateID ());
333+ if (isSlideOverCar || IsIdle ())
334+ {
335+ const PedestrianCtlState& ctlState = GetCtlState ();
336+ if (ctlState.mTurnLeft || ctlState.mTurnRight || ctlState.mRotateToDesiredAngle )
337+ {
338+ if (ctlState.mRotateToDesiredAngle )
339+ {
340+ static const float instantTurnSpeed = 360 .0f * 10 .0f ;
341+
342+ float turnSpeed = instantTurnSpeed;
343+
344+ const float angleDelta = cxx::wrap_angle_neg_180 ((ctlState.mDesiredRotationAngle - mPhysicsBody ->GetOrientation ()).to_degrees ());
345+ const float desiredSpeedPerTurn = gPhysics .GetSimulationStepTime () * turnSpeed;
346+ if (angleDelta < desiredSpeedPerTurn)
347+ {
348+ turnSpeed = angleDelta / gPhysics .GetSimulationStepTime ();
349+ }
350+
351+ if (::fabs (turnSpeed) > 1 .0f )
352+ {
353+ angularVelocity.set_angle (turnSpeed, cxx::angle_t ::units::degrees);
354+ }
355+ }
356+ else
357+ {
358+ float turnSpeed = isSlideOverCar ?
359+ gGameParams .mPedestrianTurnSpeedSlideOnCar :
360+ gGameParams .mPedestrianTurnSpeed ;
361+
362+ angularVelocity = cxx::angle_t::from_degrees (turnSpeed * (ctlState.mTurnLeft ? -1 .0f : 1 .0f ));
363+ }
364+ }
365+ }
366+
367+ mPhysicsBody ->SetAngularVelocity (angularVelocity);
368+ }
369+
328370void Pedestrian::DebugDraw (DebugRenderer& debugRender)
329371{
330372 if (mCurrentCar == nullptr )
0 commit comments