void Moose::Mating() { if (mHunger < 50) { mTargetType = ET_GRASS; SetPrey((Entity **)((BaseApp*)mApp)->mGameState->mGrass); mWanderStep = 300; SetState(ES_HUNTING); } int ChaseResult = Chase(); if (ChaseResult == 2) { mCurTarget = 0; mMoveSpeed = 0.5; mWanderStep = 50; SetPrey(0); mSterile = true; mTargetType = ET_NONE; mCurrentStep = 0; SetAnimationSpeed(200); SetState(ES_IDLE); } else if (ChaseResult == 0) { //mate got killed or ran away. mCurTarget = 0; mMoveSpeed = 0.5; mCurrentStep = 0; SetAnimationSpeed(200); SetState(ES_STALKING); } }
void Moose::Attack() { // Calls chase every update loop // Chase() attempts to move after a target // Returns 2 if it caught the target // Returns 1 if it didnt catch the target but is still chasing it // Returns 0 if the target dies before it can catch it, or runs away. int ChaseResult = Chase(); if (ChaseResult == 2) { //caught prey mCurTarget = 0; mMoveSpeed = 0.5; mWanderStep = 50; SetPrey(0); mCurrentStep = 0; mHunger = 100; mTargetType = ET_NONE; SetAnimationSpeed(200); SetState(ES_IDLE); } else if (ChaseResult == 0) { //prey got killed or ran away. mCurTarget = 0; mMoveSpeed = 0.5; mCurrentStep = 0; SetAnimationSpeed(200); SetState(ES_HUNTING); } }
void Moose::Charging() { int ChaseResult = Chase(); if (ChaseResult == 2) { //caught prey mCurTarget = 0; mMoveSpeed = 0.5; mWanderStep = 50; SetPrey(0); mCurrentStep = 0; mHunger = 100; mTargetType = ET_NONE; SetAnimationSpeed(200); SetState(ES_IDLE); } else if (ChaseResult == 0) { //caught prey mCurTarget = 0; mMoveSpeed = 0.5; mWanderStep = 50; SetPrey(0); mCurrentStep = 0; mHunger = 100; mTargetType = ET_NONE; SetAnimationSpeed(200); SetState(ES_IDLE); } }
void Unit::ReloadWeapon() { if (!IsAlive()) return; if ( gCurrentWeapon ) { if (gCurrentWeapon->Reload()) { float reloadTime = gCurrentWeapon->GetReloadTime(); string animation; string animationAfter; switch (gWeaponState) { case Hold: animation = GetAnimation("DrawReloadPutAway"); switch (gMoveState) { case Stand: case Crouch: animationAfter = GetAnimation("UpperStand"); break; case Walk: animationAfter = GetAnimation("UpperWalk"); case Run: animationAfter = GetAnimation("UpperRun"); } if (PlayingAnimation(GetAnimation("PutAway"))) PlayAnimationAfter(GetAnimation("PutAway"), animation); else PlayAnimation(animation); LoopAnimationAfter(animation, animationAfter); SetAnimationSpeed(animation, GetAnimationTime(animation) / reloadTime); break; case Aim: animation = GetAnimation("Reload"); animationAfter = GetAnimation("Aim"); if (PlayingAnimation(GetAnimation("Draw"))) PlayAnimationAfter(GetAnimation("Draw"), animation); else PlayAnimation(animation); PlayAnimationAfter(animation, animationAfter); SetAnimationSpeed(animation, GetAnimationTime(animation) / reloadTime); break; } } } }
void AnimatedEntity::native_SetAnimationSpeed(CallStruct &cs) { int id = cs.GetInt(0); float speed = cs.GetFloat(1); SetAnimationSpeed(id, speed); }
void AnimatedEntity::native_SetAnimationSpeed_2(CallStruct &cs) { String seqName = cs.GetString(0); float speed = cs.GetFloat(1); SetAnimationSpeed(seqName, speed); }
//------------------------------------------------------------------------ void CVehicleMovementHelicopter::Reset() { CVehicleMovementBase::Reset(); m_damageActual = 0.0f; ResetActions(); m_enginePower = 0.0f; m_EnginePerformance = 1.0f; m_rpmScale = 100.0f; m_isEnginePowered = false; m_actionPitch = 0.0f; m_actionRoll = 0.0f; m_actionYaw = 0.0f; m_CurrentSpeed = 0.0f; m_CurrentVel = ZERO; m_steeringDamage = ZERO; m_pNoise = &m_defaultNoise; m_pVehicle->GetGameObject()->EnableUpdateSlot(m_pVehicle, IVehicle::eVUS_EnginePowered); if(m_HoverAnim) m_HoverAnim->Reset(); SetAnimationSpeed(eVMA_Engine, (m_enginePower / m_enginePowerMax)); m_arcade.Reset(m_pVehicle, m_pEntity); }
void AnimationController::PlayReverseAnim(const String &name, const String &fadein, const String &exclusive) { if (!ViewEnabled()) return; if (!name.Length()) { LogWarning("Empty animation name for PlayReverseAnim"); return; } float fadein_ = 0.0f; if (fadein.Length()) fadein_ = ToFloat(fadein); bool exclusive_ = false; if (exclusive.Length()) exclusive_ = ToBool(exclusive); bool success; if (exclusive_) success = EnableAnimation(name, true, fadein_, false); else success = EnableExclusiveAnimation(name, true, fadein_, fadein_, false); if (!success) { StringVector anims = AvailableAnimations(); void (*log)(const String &) = LogDebug; if (anims.Size() > 0) log = LogWarning; log("Failed to play animation \"" + name + "\" in reverse on entity " + ParentEntity()->Name()); log("The entity has " + String(anims.Size()) + " animations available: " + Join(anims, ",")); SetAnimationToEnd(name); SetAnimationSpeed(name, -1.0f); } }
void Prey::Sleep() { PlayAnimation(ANIMATION_SLEEPING,true); if(CheckNightTime() == false) { SetFollowerState(FS_NORMAL); SetAnimationSpeed(200); PlayAnimation(ANIMATION_WALKING); SetState(ES_IDLE); } };
void Moose::Hunting() { Wander(); Search(); // Call this to search for your prey (only works if SetPreyList has been called successfully). // Check if the entity found a suitable target. if (mCurTarget) { SetState(ES_ATTACK); // Switch its state to attack mMoveSpeed = 2.5; // Increase it's movement speed SetAnimationSpeed(100); // Decreases the animation's time between frames (makes the animation play faster) PlayAnimation(ANIMATION_RUNNING, true); // Plays the running animation (must be set in constructor for this to work) } }
void Moose::Idle() { Wander(); // Moves around based on the values set in the constructor. if (mHunger < 50) { mTargetType = ET_GRASS; SetPrey((Entity **)((BaseApp*)mApp)->mGameState->mGrass); mWanderStep = 300; SetState(ES_HUNTING); } if (mAge > 20 && mHunger > 50 && !mSterile) { //Trigger stalking.. SetPrey((Entity **)((BaseApp *)mApp)->mGameState->mMoose); mTargetType = ET_MOOSE; mWanderStep = 300; SetState(ES_STALKING); } //collect message from the message board.. MessageBoardMessages::iterator Pos; Message CurMessage = MessageBoard::GetBoard()->CollectMessage(Pos); if (CurMessage.TargetType == ET_MOOSE) { //dismiss the message if its a false alarm. if (CurMessage.Target->GetAlive() == false || CurMessage.Target->GetType() == ET_CHUCK) { MessageBoard::GetBoard()->DismissMessage(Pos); return; } //check the distance between this moose and the sender float dist = sqrt((GetX() - CurMessage.Poster->GetX()) * (GetX() - CurMessage.Poster->GetX()) + (GetY() - CurMessage.Poster->GetY()) * (GetY() - CurMessage.Poster->GetY())); if (dist < 300) { MessageBoard::GetBoard()->DismissMessage(Pos); mTargetType = ET_PREDATOR; mCurTarget = CurMessage.Target; mMoveSpeed = 2.5; // Increase it's movement speed SetAnimationSpeed(100); // Decreases the animation's time between frames (makes the animation play faster) PlayAnimation(ANIMATION_CHARGING, true); SetState(ES_CHARGING); } } }
void AnimationController::SetAnimSpeed(const String &name, const String &animspeed) { if (!name.Length()) { LogWarning("Empty animation name for SetAnimSpeed"); return; } if (!animspeed.Length()) { LogWarning("No animation speed specified for SetAnimSpeed"); return; } float speed = ToFloat(animspeed); SetAnimationSpeed(name, speed); }
//------------------------------------------------------------------------ void CVehicleMovementHelicopter::Reset() { CVehicleMovementBase::Reset(); m_playerControls.Reset(); m_isEnginePowered = false; m_steeringDamage = 0.0f; m_damageActual = 0.0f; m_turbulence = 0.0f; ResetActions(); m_powerPID.Reset(); m_liftPID.Reset(); m_yawPID.Reset(); // high-level controller Ang3 angles = m_pEntity->GetWorldAngles(); m_desiredDir = angles.z; m_desiredHeight = m_pEntity->GetWorldPos().z; m_lastDir = m_desiredDir; m_enginePower = 0.0f; m_isTouchingGround = false; m_timeOnTheGround = 50.0f; m_desiredPitch = 0.0f; m_desiredRoll = 0.0f; m_engineForce = 0.0f; m_noHoveringTimer = 0.0f; m_xyHelp = 0.0f; m_liftPitchAngle = 0.0f; m_relaxTimer = 0.0f; m_velDamp = 0.0f; SetAnimationSpeed(eVMA_Engine, (m_enginePower / m_enginePowerMax)); }
Moose::Moose(SimianBase * theApp, char * theName) : Entity(theApp, theName) { SetType(ET_MOOSE); SetState(ES_IDLE); SetFrames(6, 3); int WalkLeft[] = {0,1,0,2}; int WalkRight[] = {5,3,5,4}; int WalkUp[] = {9,10,9,11}; int WalkDown[] = {6,7,6,8}; int WalkLength[] = {4,4,4,4}; int StandLeft[] = {0}; int StandRight[] = {5}; int StandUp[] = {9}; int StandDown[] = {6}; int StandLength[] = {1,1,1,1}; int ChargeLeft[] = {12, 13}; int ChargeRight[] = {15, 16}; int ChargeUp[] = {10, 11}; int ChargeDown[] = {7, 8}; int ChargeLength[] = {2,2,2,2}; ANIMATION_RUNNING = AddAnimation(WalkUp, WalkDown, WalkLeft, WalkRight, WalkLength); ANIMATION_STANDING = AddAnimation(StandUp, StandDown, StandLeft, StandRight, StandLength); ANIMATION_WALKING = AddAnimation(WalkUp, WalkDown, WalkLeft, WalkRight, WalkLength); ANIMATION_EATING = AddAnimation(StandUp, StandDown, StandLeft, StandRight, StandLength); ANIMATION_CHARGING = AddAnimation(ChargeUp, ChargeDown, ChargeLeft, ChargeRight, ChargeLength); SetAnimationSpeed(200); PlayAnimation(ANIMATION_WALKING); mWanderStep = 50; mPauseTime = 1000; mMoveSpeed = 0.5; mSearchDistance = 200; mSearchAngle = 60; mTargetType = ET_GRASS; mHungerTimer = 1000; }
//------------------------------------------------------------------------ void CVehicleMovementHelicopter::Update(const float deltaTime) { FUNCTION_PROFILER( GetISystem(), PROFILE_GAME ); CVehicleMovementBase::Update(deltaTime); UpdateDamages(deltaTime); UpdateEngine(deltaTime); { CryAutoCriticalSection lk(m_lock); m_netActionSync.Read(this); if (gEnv->bServer) { m_sendTimer -= deltaTime; if (m_sendTimer<=0.f) { m_netActionSync.Write(this); CHANGED_NETWORK_STATE(m_pVehicle, m_updateAspects); m_sendTimer = m_sendTime; } } } SetSoundParam(eSID_Run, "rpm_scale", m_rpmScale); // update animation if(m_isEngineGoingOff) { if(m_enginePower > 0.0f) { UpdateEngine(deltaTime); } else { m_enginePower = 0.0f; } } SetAnimationSpeed(eVMA_Engine, (m_enginePower / m_enginePowerMax)); }
void Moose::Stalking() { Wander(); Search(); if (mHunger < 50) { mTargetType = ET_GRASS; SetPrey((Entity **)((BaseApp*)mApp)->mGameState->mGrass); mWanderStep = 300; SetState(ES_HUNTING); } if (mCurTarget) { SetState(ES_MATING); // Switch its state to attack mMoveSpeed = 1.5; // Increase it's movement speed SetAnimationSpeed(100); // Decreases the animation's time between frames (makes the animation play faster) PlayAnimation(ANIMATION_WALKING); } }
void Player::Update(const GameContext& gameContext) { if(m_Health > 0) { auto animator = m_pModelComp->GetAnimator(); animator->SetAnimationSpeed(0.5f * m_SpeedUp); animator->SetPlayReversed(false); float deltaTime = gameContext.pGameTime->GetElapsed(); // blur effect if(m_DamageTimer > 0) { m_DamageTimer -= 0.55f * deltaTime; } Clamp<float>(m_DamageTimer, 0.2f, 0); // healing float healTime = 4.5f, healAmount = 3.25f; m_LastDamaged += deltaTime; if(m_LastDamaged >= healTime) { m_Health += healAmount * deltaTime; } Clamp<float>(m_Health,150,0); // raycasting m_ShootTimer += deltaTime; if(gameContext.pInput->IsActionTriggered(GameInput::SHOOT) && m_ShootTimer > 0.4f) { Raycast(gameContext); m_ShootTimer = 0; } // invulnerability if(m_Invulnerable) { m_InvulTimer += deltaTime; if(m_InvulTimer >= 10) { m_Invulnerable = false; m_InvulTimer = 0; } } ///// XMFLOAT2 look = XMFLOAT2(0,0); float lookSpeed = 4.f; //if(gameContext.pInput->IsMouseButtonDown(VK_LBUTTON)) //{ // auto mouseMove = gameContext.pInput->GetMouseMovement(); // //gameContext.pInput-> // look.x = static_cast<float>(mouseMove.x); // look.y = static_cast<float>(mouseMove.y); //} if(gameContext.pInput->IsKeyboardKeyDown(VK_RIGHT)) look.x = lookSpeed; if(gameContext.pInput->IsKeyboardKeyDown(VK_LEFT)) look.x = -lookSpeed; if(gameContext.pInput->IsKeyboardKeyDown(VK_UP)) look.y = lookSpeed * 0.75f; if(gameContext.pInput->IsKeyboardKeyDown(VK_DOWN)) look.y = -lookSpeed * 0.75f; if(look.x == 0 && look.y == 0) { look = gameContext.pInput->GetThumbstickPosition(false); } m_TotalYaw += look.x * m_RotationSpeed * deltaTime; m_TotalPitch += look.y * m_RotationSpeed * deltaTime; m_CamRot += look.y * m_RotationSpeed * deltaTime; GetTransform()->Rotate(0, m_TotalYaw, 0); Clamp<float>(m_CamRot, 25, -10); XMFLOAT3 camPos = m_CamObj->GetTransform()->GetPosition(); m_CamObj->GetTransform()->Translate(camPos.x, 7.5f + m_CamRot * 0.75f, camPos.z); m_CamObj->GetTransform()->Rotate(m_CamRot, 0, 0); // Reset velocity m_Velocity = XMFLOAT3(0,m_Velocity.y,0); if(m_pController->GetCollisionFlags() == PxControllerCollisionFlag::eCOLLISION_DOWN) { m_Velocity.y = 0; m_JumpVelocity = 0; } else { m_JumpVelocity -= m_JumpAcceleration * deltaTime; } XMFLOAT3 forward = GetTransform()->GetForward(); XMFLOAT3 right = GetTransform()->GetRight(); bool isMoving = false; #pragma region "input" if(gameContext.pInput->IsActionTriggered(GameInput::MOVEUP)) { isMoving = true; m_Velocity.x += forward.x * m_RunVelocity * m_SpeedUp; m_Velocity.z += forward.z * m_RunVelocity * m_SpeedUp; } if(gameContext.pInput->IsActionTriggered(GameInput::MOVEDOWN)) { isMoving = true; m_Velocity.x -= forward.x * m_RunVelocity * m_SpeedUp; m_Velocity.z -= forward.z * m_RunVelocity * m_SpeedUp; animator->SetPlayReversed(true); } float sideMove = 0.85f; if(gameContext.pInput->IsActionTriggered(GameInput::MOVERIGHT)) { isMoving = true; m_Velocity.x += right.x * m_RunVelocity * sideMove * m_SpeedUp; m_Velocity.z += right.z * m_RunVelocity * sideMove * m_SpeedUp; } if(gameContext.pInput->IsActionTriggered(GameInput::MOVELEFT)) { isMoving = true; m_Velocity.x -= right.x * m_RunVelocity * sideMove * m_SpeedUp; m_Velocity.z -= right.z * m_RunVelocity * sideMove * m_SpeedUp; } #pragma endregion if(!isMoving) { animator->Pause(); m_Velocity.x = 0.0f; m_Velocity.z = 0.0f; } else { animator->Play(); } XMFLOAT3 tempVelocity = m_Velocity; tempVelocity.y += m_JumpVelocity; XMFLOAT3 delta = tempVelocity; delta.x = tempVelocity.x * deltaTime; delta.y = tempVelocity.y * deltaTime; delta.z = tempVelocity.z * deltaTime; m_pController->Move(delta); // Speed up if(m_SpeedUp > 1) { m_SpeedUp -= 0.0715f * deltaTime; } if(m_SpeedUp < 1) { m_SpeedUp = 1; } // Add fire if(m_AddFire) { auto fire = new Fire(); AddChild(fire); fire->GetTransform()->Scale(2,2,2); m_Fires.push_back(fire); m_AddFire = false; } // Delete fires //Fire* toDel = nullptr; //for(Fire* fire : m_Fires) // if(fire) // if(fire->IsDone()) // toDel = fire; //if(toDel) //{ // for(auto it = m_Fires.begin(); it != m_Fires.end();) // { // if(toDel == *it) // { // RemoveChild(*it); // it = m_Fires.erase(it); // } // else // ++it; // } //} } }
//------------------------------------------------------------------------ void CVehicleMovementHelicopter::Update(const float deltaTime) { FUNCTION_PROFILER(GetISystem(), PROFILE_GAME); CVehicleMovementBase::Update(deltaTime); CryAutoCriticalSection lk(m_lock); if(m_isTouchingGround) { m_timeOnTheGround += deltaTime; m_isTouchingGround = false; } else { m_timeOnTheGround = 0.0f; } // ai specific sound matter if(m_soundMasterVolume != m_vehicleVolume) { float vol = m_soundMasterVolume; if(m_vehicleVolume == 0) CVehicleMovementBase::SetSoundMasterVolume(m_vehicleVolume); else if(vol < m_vehicleVolume) { vol +=deltaTime; if(vol > m_vehicleVolume) vol = m_vehicleVolume; CVehicleMovementBase::SetSoundMasterVolume(vol); } else if(vol > m_vehicleVolume) { vol -=deltaTime; if(vol < m_vehicleVolume) vol = m_vehicleVolume; CVehicleMovementBase::SetSoundMasterVolume(vol); } } // update animation if(m_isEngineGoingOff) { if(m_enginePower > 0.0f) { UpdateEngine(deltaTime); } else { m_enginePower = 0.0f; } } SetAnimationSpeed(eVMA_Engine, (m_enginePower / m_enginePowerMax)); #if ENABLE_VEHICLE_DEBUG IActor *pActor = m_pActorSystem->GetActor(m_actorId); int profile = g_pGameCVars->v_profileMovement; if((profile == 1 && pActor && pActor->IsClient()) || profile == 2) { IRenderer *pRenderer = gEnv->pRenderer; float color[4] = {1,1,1,1}; Ang3 localAngles = m_pEntity->GetWorldAngles(); m_mass = m_statusDyn.mass; Vec3 &velocity = m_statusDyn.v; Vec3 &angVelocity = m_statusDyn.w; pRenderer->Draw2dLabel(5.0f, 0.0f, 2.0f, color, false, "Helicopter movement"); Vec3 i; i = m_control.impulse.GetNormalizedSafe(); pRenderer->Draw2dLabel(5.0f, 85.0f, 1.5f, color, false, "impulse: %f, %f, %f (%f, %f, %f)", m_control.impulse.x, m_control.impulse.y, m_control.impulse.z, i.x, i.y, i.z); pRenderer->Draw2dLabel(5.0f, 100.0f, 1.5f, color, false, "angImpulse: %f, %f, %f", m_control.angImpulse.x, m_control.angImpulse.y, m_control.angImpulse.z); i = velocity.GetNormalizedSafe(); pRenderer->Draw2dLabel(5.0f, 115.0f, 1.5f, color, false, "velocity: %f, %f, %f (%f) (%f, %f, %f)", velocity.x, velocity.y, velocity.z, velocity.GetLength(), i.x, i.y, i.z); pRenderer->Draw2dLabel(5.0f, 130.0f, 1.5f, color, false, "angular velocity: %f, %f, %f", RAD2DEG(angVelocity.x), RAD2DEG(angVelocity.y), RAD2DEG(angVelocity.z)); pRenderer->Draw2dLabel(5.0f, 160.0f, 1.5f, color, false, "angles: %f, %f, %f (%f, %f, %f)", RAD2DEG(localAngles.x), localAngles.y, localAngles.z, RAD2DEG(localAngles.x), RAD2DEG(localAngles.y), RAD2DEG(localAngles.z)); pRenderer->Draw2dLabel(5.0f, 175.0f, 1.5f, color, false, "m_rpmScale: %f, damage: %f, damageActual: %f, turbulence: %f", m_rpmScale, m_damage, m_damageActual, m_turbulence); pRenderer->Draw2dLabel(5.0f, 190.0f, 1.5f, color, false, "m_turnAction: %f, actionYaw: %f, targetRotation: %f, %f, %f", m_turnAction, m_actionYaw, RAD2DEG(m_rotateTarget.x), RAD2DEG(m_rotateTarget.y), RAD2DEG(m_rotateTarget.z)); pRenderer->Draw2dLabel(5.0f, 220.0f, 1.5f, color, false, "lift: %f, engineForce: %f, hoveringPower: %f, desiredHeight: %f, boost: %d, fwdAction: %f", m_liftAction, m_engineForce, m_hoveringPower, m_desiredHeight, Boosting(), m_forwardAction); pRenderer->Draw2dLabel(5.0f, 235.0f, 1.5f, color, false, "pitchAction: %f, rollAction: %f", m_actionPitch, m_actionRoll); pRenderer->Draw2dLabel(5.0f, 250.0f, 1.5f, color, false, "desiredPitch: %f, desiredRoll: %f", m_desiredPitch, m_desiredRoll); Vec3 direction = m_pEntity->GetWorldTM().GetColumn(1); pRenderer->Draw2dLabel(5.0f, 270.0f, 1.5f, color, false, "fwd direction: %.2f, %.2f, %.2f", direction.x, direction.y, direction.z); pRenderer->Draw2dLabel(5.0f, 285.0f, 1.5f, color, false, "workingUpDir: %.2f, %.2f, %.2f", m_workingUpDir.x, m_workingUpDir.y, m_workingUpDir.z); pRenderer->Draw2dLabel(5.0f, 300.0f, 1.5f, color, false, "accel: %f", m_playerAcceleration); } #endif }
void Prey::SUBFSM() { if (FSTATE == FS_SLEEPING) { Sleep(); } else { if (MSTATE ==MS_ALERTED) { if (CheckNightTime()==false) MSTATE = MS_NORMAL; } if (AmLeader) { if ((mCurState!=ES_EVADING)&&(mCurState!=ES_MATING)&&(mCurState!=ES_ATTACK)) { LeaderHunterCheck(); } if (MSTATE == MS_NORMAL) { if(CheckNightTime()) { SetLeaderState(LS_PATROL); SetAnimationSpeed(200); PlayAnimation(ANIMATION_STANDING); SetState(ES_IDLE); } } switch(LSTATE) { case LS_NORMAL: Wander(); break; case LS_PATROL: Patrol(); break; default: break; } } else { if (MSTATE == MS_NORMAL) { if(CheckNightTime()) { SetFollowerState(FS_SLEEPING); SetAnimationSpeed(200); SetState(ES_IDLE); } } if (MyLeader) CheckLeaderAlive(); if (LeaderAlive) { switch(FSTATE) { case FS_NORMAL: FollowLeader(); break; case FS_CHASELEADER: ChaseLeader(); break; default: break; } } else { Wander(); } } } }
void Unit::Update(float DeltaTime, Terrain* TerrainInstance) { if ( IsAlive() && gHealth.first <= 0 ) { SetWeaponState( Hold ); DropWeapon(); Kill(); StopAllAnimations(); PlayAnimation("Death"); PlayAnimationAfter("Death", "Dead"); SoundManager::GetInstance()->Play( gDeathSound, SFX, false ); if (!PlayingAnimation("Death")) { SetState( Dead ); return; } } GameObject::Update(DeltaTime, TerrainInstance); if ( GetState() == Dying ) return; XMVECTOR vel = XMLoadFloat3(&GetFloat3Value( Velocity )); if (!XMVector3Equal(vel, XMVectorZero())) { XMVECTOR dir = XMLoadFloat3(&GetFloat3Value( Direction )); XMVECTOR angleV = XMVector3AngleBetweenVectors(dir, vel); float angle; XMStoreFloat(&angle, angleV); XMVECTOR crossV = XMVector3Cross(dir, vel); if (XMVectorGetY(crossV) < 0) angle *= -1; //cout << 180 * angle / PI << endl; if (fabs(angle) <= PI * 0.25f) gMoveDirection = Forward; else if (fabs(angle) > PI * 0.75f) gMoveDirection = Back; else if (angle < 0) gMoveDirection = Left; else if (angle > 0) gMoveDirection = Right; XMVECTOR L = XMVector3Length(vel); float speed; XMStoreFloat(&speed, L); speed /= UnitsPerMeter; switch (gMoveDirection) { case Forward: if (speed > 1.05f * gWalkSpeed) { SetMoveState(Run); SetAnimationSpeed("Run", speed); SetAnimationSpeed(GetAnimation("UpperRun"), speed); } else { SetMoveState(Walk); SetAnimationSpeed("Walk", speed); } break; case Back: SetMoveState(Walk); SetAnimationSpeed("Back", speed); break; case Right: SetMoveState(Walk); SetAnimationSpeed("SideStepRight", speed); break; case Left: SetMoveState(Walk); SetAnimationSpeed("SideStepLeft", speed); break; } } else { gMoveDirection = None; if (!Crouching()) SetMoveState(Stand); } if ( gCurrentWeapon ) { XMFLOAT3 handPos; XMFLOAT4 handRot; XMVECTOR pos = XMLoadFloat3(&GetFloat3Value( Position )); XMVECTOR dir = XMLoadFloat3(&GetFloat3Value( Direction )); XMVECTOR lv = XMVector3Length(dir); bool gotJointPos = false; bool gotJointRot = false; if (m_ModelInstance) { gotJointPos = GetJointPosition("RightHand", handPos); gotJointRot = GetJointRotation("RightHand", handRot); } if (!gotJointPos) { pos += dir * (GetRadius() - 10); XMStoreFloat3(&handPos, pos); } if (gCurrentWeapon->NeedReload()) { ReloadWeapon(); } //gWeapon->Update(DeltaTime); //gWeapon->MoveTo( position ); gCurrentWeapon->MoveTo( handPos ); XMFLOAT3 weaponPos; if (gCurrentWeapon->GetJointPosition("RightHand", weaponPos)) { XMStoreFloat3(&handPos, XMLoadFloat3(&handPos) + (XMLoadFloat3(&handPos) - XMLoadFloat3(&weaponPos))); gCurrentWeapon->MoveTo( handPos ); } if (gotJointRot) { gCurrentWeapon->SetRotation( handRot ); } else gCurrentWeapon->SetRotation( GetQuaternation() ); } /* else { LoopAnimation("PistolUpperWalk"); } */ }
//------------------------------------------------------------------------ void CVehicleMovementStdBoat::Update(const float deltaTime) { CVehicleMovementBase::Update(deltaTime); SetAnimationSpeed(eVMA_Engine, abs(m_rpmScaleSgn)); if (m_inWater) { SetSoundParam(eSID_Run, "slip", 0.2f*abs(m_localSpeed.x)); } #if ENABLE_VEHICLE_DEBUG if (IsProfilingMovement() && g_pGameCVars->v_profileMovement != 2) { IEntity* pEntity = m_pVehicle->GetEntity(); const Matrix34& wTM = pEntity->GetWorldTM(); Matrix34 wTMInv = wTM.GetInvertedFast(); const SVehiclePhysicsStatus* physStatus = &m_physStatus[k_mainThread]; Vec3 localW = physStatus->q * physStatus->w; float speed = physStatus->v.len2() > 0.001f ? physStatus->v.len() : 0.f; float speedRatio = min(1.f, speed/(m_maxSpeed*m_factorMaxSpeed)); float absPedal = abs(m_movementAction.power); float absSteer = abs(m_movementAction.rotateYaw); static const float fSubmergedMin = 0.01f; static const float fWaterLevelMaxDiff = 0.15f; // max allowed height difference between propeller center and water level Vec3 worldPropPos = wTM * m_pushOffset; float waterLevelWorld = gEnv->p3DEngine->GetWaterLevel( &worldPropPos ); float fWaterLevelDiff = worldPropPos.z - waterLevelWorld; // wave stuff float waveFreq = 1.f; waveFreq += 3.f*speedRatio; float kx = m_waveIdleStrength.x*(m_waveRandomMult+0.3f) * (1.f-speedRatio + m_waveSpeedMult*speedRatio); float ky = m_waveIdleStrength.y * (1.f - 0.5f*absPedal - 0.5f*absSteer); Vec3 waveLoc = m_massOffset; waveLoc.y += speedRatio*min(0.f, m_pushOffset.y-m_massOffset.y); waveLoc = wTM * waveLoc; IRenderer* pRenderer = gEnv->pRenderer; static float color[4] = {1,1,1,1}; float colorRed[4] = {1,0,0,1}; float colorGreen[4] = {0,1,0,1}; float y=50.f, step1=15.f, step2=20.f, size1=1.3f, size2=1.5f; pRenderer->Draw2dLabel(5.0f, y, size2, color, false, "Boat movement"); pRenderer->Draw2dLabel(5.0f, y+=step2, size1, color, false, "Speed: %.1f (%.1f km/h)", speed, speed*3.6f); pRenderer->Draw2dLabel(5.0f, y+=step1, size1, color, false, "LocalW.z norm: %.2f", abs(localW.z)/m_turnRateMax); if (m_velLift > 0.f) { pRenderer->Draw2dLabel(5.0f, y+=step2, size1, m_lifted ? colorGreen : color, false, m_lifted ? "Lifted" : "not lifted"); //pRenderer->Draw2dLabel(5.0f, y+=step2, size1, color, false, "Impulse lift: %.0f", liftImp.impulse.len()); } pRenderer->Draw2dLabel(5.0f, y+=step1, size1, physStatus->submergedFraction > fSubmergedMin ? color : colorRed, false, "Submerged: %.2f", physStatus->submergedFraction); pRenderer->Draw2dLabel(5.0f, y+=step1, size1, fWaterLevelDiff < fWaterLevelMaxDiff ? color : colorRed, false, "WaterLevel: %.2f (max: %.2f)", fWaterLevelDiff, fWaterLevelMaxDiff); pRenderer->Draw2dLabel(5.0f, y+=step2, size2, color, false, "Driver input"); pRenderer->Draw2dLabel(5.0f, y+=step2, size1, color, false, "power: %.2f", m_movementAction.power); pRenderer->Draw2dLabel(5.0f, y+=step1, size1, color, false, "steer: %.2f", m_movementAction.rotateYaw); pRenderer->Draw2dLabel(5.0f, y+=step2, size2, color, false, "Propelling"); //pRenderer->Draw2dLabel(5.0f, y+=step2, size1, color, false, "turnAccel (norm/real): %.2f / %.2f", turnAccelNorm, turnAccel); //pRenderer->Draw2dLabel(5.0f, y+=step1, size1, color, false, "Impulse acc: %.0f", linearImp.impulse.len()); //pRenderer->Draw2dLabel(5.0f, y+=step1, size1, color, false, "Impulse steer/damp: %.0f", angularImp.angImpulse.len()); //pRenderer->Draw2dLabel(5.0f, y+=step1, size1, color, false, "Impulse corner: %.0f", dampImp.impulse.len()); pRenderer->Draw2dLabel(5.0f, y+=step2, size2, color, false, "Waves"); pRenderer->Draw2dLabel(5.0f, y+=step2, size1, color, false, "timer: %.1f", m_waveTimer); pRenderer->Draw2dLabel(5.0f, y+=step1, size1, color, false, "frequency: %.2f", waveFreq); pRenderer->Draw2dLabel(5.0f, y+=step1, size1, color, false, "random: %.2f", m_waveRandomMult); pRenderer->Draw2dLabel(5.0f, y+=step1, size1, color, false, "kX: %.2f", kx); pRenderer->Draw2dLabel(5.0f, y+=step1, size1, color, false, "kY: %.2f", ky); if (Boosting()) pRenderer->Draw2dLabel(5.0f, y+=step1, size1, color, false, "Boost: %.2f", m_boostCounter); IRenderAuxGeom* pGeom = pRenderer->GetIRenderAuxGeom(); ColorB colorB(0,255,0,255); pRenderer->DrawLabel(worldPropPos, 1.3f, "WL: %.2f", waterLevelWorld); pGeom->DrawSphere(worldPropPos, 0.15f, colorB); pGeom->DrawSphere(waveLoc, 0.25f, colorB); pGeom->DrawLine(waveLoc, colorB, waveLoc+Vec3(0,0,2), colorB); // impulses //DrawImpulse(linearImp, Vec3(0,0,1), 3.f/deltaTime, ColorB(255,0,0,255)); //DrawImpulse(angularImp, Vec3(0,0,1), 2.f/deltaTime, ColorB(128,0,0,255)); //DrawImpulse(liftImp, Vec3(0,0,6), 2.f/deltaTime, ColorB(0,0,255,255)); } #endif }