public void SetDisplacementMode(EntityDisplacementModes newValue, Vector3D WorldEyePosition) { // Moving from flight behavior to first person behavior. // Need to ignore camera roll, but retain existing pitch and heading. if (_displacementMode == EntityDisplacementModes.FreeFlying && newValue == EntityDisplacementModes.Walking) { InitRotation(WorldEyePosition.AsVector3(), WorldEyePosition.AsVector3() + _entityEyeZAxis, Vector3.UnitY); } _displacementMode = newValue; }
/// <summary> /// Compute new entity position following activated inputs /// </summary> /// <param name="mode">The current displacement mode</param> /// <param name="timeSpent">Elapsed time since last call</param> private void EntityMovementsOnInputs(EntityDisplacementModes mode, ref GameTime timeSpent) { switch (mode) { case EntityDisplacementModes.Swiming: SwimmingFreeFirstPersonMove(ref timeSpent); break; case EntityDisplacementModes.Dead: DeadMove(); break; case EntityDisplacementModes.Flying: case EntityDisplacementModes.God: FreeFirstPersonMove(); break; case EntityDisplacementModes.Walking: if (_physicSimu.isInContactWithLadder) { LadderFreeFirstPersonMove(ref timeSpent); } else { if (_physicSimu.OnGround) { WalkingFirstPersonOnGround(ref timeSpent); _physicSimu.StopMovementAction = false; } else { WalkingFirstPersonNotOnGround(ref timeSpent); } } break; default: break; } }
private void PhysicOnEntity(EntityDisplacementModes mode, ref GameTime timeSpent) { if (_stopMovedAction && _groundCubeProgile.SlidingValue == 0) { _stopMovedAction = false; } switch (mode) { case EntityDisplacementModes.Dead: _physicSimu.Friction = 0f; PhysicSimulation(ref timeSpent); break; case EntityDisplacementModes.God: case EntityDisplacementModes.Flying: _physicSimu.Friction = 0f; #if !DEBUG PhysicSimulation(ref timeSpent); //Apply physic constraint on new compute location #endif break; case EntityDisplacementModes.Swiming: _physicSimu.Friction = 0.3f; PhysicSimulation(ref timeSpent); //Apply physic constraint on new compute location break; case EntityDisplacementModes.Walking: if (_physicSimu.isInContactWithLadder) { if (!_physicSimu.OnGround) { _physicSimu.AirFriction = 0.25f; _physicSimu.Friction = 0.25f; } else { _physicSimu.AirFriction = 0; if (_stopMovedAction == false) { _physicSimu.Friction = _groundCubeProgile.Friction; //0.25f; } else { //I did stop to move, but I'm on a sliding block => Will slide a little before ending movement _physicSimu.Friction = _groundCubeProgile.SlidingValue; } } PhysicSimulation(ref timeSpent); //Apply physic constraint on new compute location break; } if (_physicSimu.OnGround) { _physicSimu.AirFriction = 0.0f; if (_stopMovedAction == false) { _physicSimu.Friction = _groundCubeProgile.Friction; //0.25f; } else { //I did stop to move, but I'm on a sliding block => Will slide a little before ending movement _physicSimu.Friction = _groundCubeProgile.SlidingValue; } } else { _physicSimu.Friction = 0.0f; _physicSimu.AirFriction = 0.07f; } PhysicSimulation(ref timeSpent); //Apply physic constraint on new compute location break; default: break; } }