mirror of
https://gitlab.com/GaryOderNichts/re3-wiiu.git
synced 2024-11-23 17:49:16 +01:00
heli AI fix
This commit is contained in:
parent
9ab3683148
commit
17dd26e1ca
@ -2645,7 +2645,7 @@ void CCarCtrl::SteerAIHeliTowardsTargetCoors(CAutomobile* pHeli)
|
|||||||
{
|
{
|
||||||
if (pHeli->m_aWheelSpeed[1] < 0.22f)
|
if (pHeli->m_aWheelSpeed[1] < 0.22f)
|
||||||
pHeli->m_aWheelSpeed[1] += 0.001f;
|
pHeli->m_aWheelSpeed[1] += 0.001f;
|
||||||
if (pHeli->m_aWheelSpeed[1] < 0.22f)
|
if (pHeli->m_aWheelSpeed[1] < 0.15f)
|
||||||
return;
|
return;
|
||||||
CVector2D vecToTarget = pHeli->AutoPilot.m_vecDestinationCoors - pHeli->GetPosition();
|
CVector2D vecToTarget = pHeli->AutoPilot.m_vecDestinationCoors - pHeli->GetPosition();
|
||||||
float distanceToTarget = vecToTarget.Magnitude();
|
float distanceToTarget = vecToTarget.Magnitude();
|
||||||
@ -2654,7 +2654,8 @@ void CCarCtrl::SteerAIHeliTowardsTargetCoors(CAutomobile* pHeli)
|
|||||||
#else
|
#else
|
||||||
float speed = pHeli->AutoPilot.m_nCruiseSpeed * 0.01f;
|
float speed = pHeli->AutoPilot.m_nCruiseSpeed * 0.01f;
|
||||||
#endif
|
#endif
|
||||||
if (distanceToTarget >= 100.0f)
|
float tmp = speed;
|
||||||
|
if (distanceToTarget <= 100.0f)
|
||||||
{
|
{
|
||||||
if (distanceToTarget > 75.0f)
|
if (distanceToTarget > 75.0f)
|
||||||
speed *= 0.7f;
|
speed *= 0.7f;
|
||||||
@ -2668,34 +2669,33 @@ void CCarCtrl::SteerAIHeliTowardsTargetCoors(CAutomobile* pHeli)
|
|||||||
float resistance = Pow(0.997f, CTimer::GetTimeStep());
|
float resistance = Pow(0.997f, CTimer::GetTimeStep());
|
||||||
pHeli->m_vecMoveSpeed.x *= resistance;
|
pHeli->m_vecMoveSpeed.x *= resistance;
|
||||||
pHeli->m_vecMoveSpeed.y *= resistance;
|
pHeli->m_vecMoveSpeed.y *= resistance;
|
||||||
vecAdvanceThisFrame -= pHeli->m_vecMoveSpeed;
|
CVector2D vecSpeedDirection = vecAdvanceThisFrame - pHeli->m_vecMoveSpeed;
|
||||||
CVector2D vecSpeedChange = vecAdvanceThisFrame - pHeli->m_vecMoveSpeed;
|
float vecSpeedChangeLength = vecSpeedDirection.Magnitude();
|
||||||
float vecSpeedChangeLength = vecSpeedChange.Magnitude();
|
vecSpeedDirection.Normalise();
|
||||||
vecSpeedChange.Normalise();
|
|
||||||
float changeMultiplier = 0.002f * CTimer::GetTimeStep();
|
float changeMultiplier = 0.002f * CTimer::GetTimeStep();
|
||||||
if (distanceToTarget < 5.0f)
|
if (distanceToTarget < 5.0f)
|
||||||
changeMultiplier /= 5.0f;
|
changeMultiplier /= 5.0f;
|
||||||
if (vecSpeedChangeLength < changeMultiplier)
|
if (vecSpeedChangeLength < changeMultiplier)
|
||||||
pHeli->AddToMoveSpeed(vecAdvanceThisFrame);
|
pHeli->SetMoveSpeed(vecAdvanceThisFrame.x, vecAdvanceThisFrame.y, pHeli->GetMoveSpeed().z);
|
||||||
else
|
else
|
||||||
pHeli->AddToMoveSpeed(vecSpeedChange * changeMultiplier);
|
pHeli->AddToMoveSpeed(vecSpeedDirection * changeMultiplier);
|
||||||
pHeli->SetPosition(pHeli->GetPosition() + CVector(CTimer::GetTimeStep() * pHeli->GetMoveSpeed().x, CTimer::GetTimeStep() * pHeli->GetMoveSpeed().y, 0.0f));
|
pHeli->GetMatrix().Translate(CTimer::GetTimeStep() * pHeli->GetMoveSpeed().x, CTimer::GetTimeStep() * pHeli->GetMoveSpeed().y, 0.0f);
|
||||||
float ZTarget = pHeli->AutoPilot.m_vecDestinationCoors.z;
|
float ZTarget = pHeli->AutoPilot.m_vecDestinationCoors.z;
|
||||||
if (CTimer::GetTimeInMilliseconds() & 0x800) // switch every ~2 seconds
|
if (CTimer::GetTimeInMilliseconds() & 0x800) // switch every ~2 seconds
|
||||||
ZTarget += 2.0f;
|
ZTarget += 2.0f;
|
||||||
float ZSpeedTarget = (ZTarget - pHeli->GetPosition().z) * 0.01f;
|
float ZSpeedTarget = (ZTarget - pHeli->GetPosition().z) * 0.01f;
|
||||||
float ZSpeedChangeTarget = ZSpeedTarget - pHeli->GetMoveSpeed().z;
|
float ZSpeedChangeTarget = ZSpeedTarget - pHeli->GetMoveSpeed().z;
|
||||||
float ZSpeedChangeMax = 0.01f * CTimer::GetTimeStep();
|
float ZSpeedChangeMax = 0.001f * CTimer::GetTimeStep();
|
||||||
if (!pHeli->bHeliDestroyed) {
|
if (!pHeli->bHeliDestroyed) {
|
||||||
if (Abs(ZSpeedChangeTarget) < ZSpeedChangeMax)
|
if (Abs(ZSpeedChangeTarget) < ZSpeedChangeMax)
|
||||||
pHeli->SetMoveSpeed(pHeli->GetMoveSpeed().x, pHeli->GetMoveSpeed().y, ZSpeedTarget);
|
pHeli->SetMoveSpeed(pHeli->GetMoveSpeed().x, pHeli->GetMoveSpeed().y, ZSpeedTarget);
|
||||||
else if (ZSpeedChangeTarget < 0.0f)
|
else if (ZSpeedChangeTarget < 0.0f)
|
||||||
pHeli->AddToMoveSpeed(0.0f, 0.0f, -1.5f * ZSpeedChangeMax);
|
pHeli->AddToMoveSpeed(0.0f, 0.0f, -ZSpeedChangeMax);
|
||||||
else
|
else
|
||||||
pHeli->AddToMoveSpeed(0.0f, 0.0f, ZSpeedChangeMax);
|
pHeli->AddToMoveSpeed(0.0f, 0.0f, 1.5f * ZSpeedChangeMax);
|
||||||
}
|
}
|
||||||
pHeli->SetPosition(pHeli->GetPosition() + CVector(0.0f, 0.0f, CTimer::GetTimeStep() * pHeli->GetMoveSpeed().z));
|
pHeli->GetMatrix().Translate(0.0f, 0.0f, CTimer::GetTimeStep() * pHeli->GetMoveSpeed().z);
|
||||||
pHeli->SetTurnSpeed(pHeli->GetTurnSpeed().x, pHeli->GetTurnSpeed().y, pHeli->GetTurnSpeed().z * Pow(0.99f, CTimer::GetTimeStep()));
|
pHeli->m_vecTurnSpeed.z *= Pow(0.99f, CTimer::GetTimeStep());
|
||||||
float ZTurnSpeedTarget;
|
float ZTurnSpeedTarget;
|
||||||
if (distanceToTarget < 8.0f && pHeli->m_fHeliOrientation < 0.0f)
|
if (distanceToTarget < 8.0f && pHeli->m_fHeliOrientation < 0.0f)
|
||||||
ZTurnSpeedTarget = 0.0f;
|
ZTurnSpeedTarget = 0.0f;
|
||||||
@ -2703,6 +2703,7 @@ void CCarCtrl::SteerAIHeliTowardsTargetCoors(CAutomobile* pHeli)
|
|||||||
float fAngleTarget = CGeneral::GetATanOfXY(vecToTarget.x, vecToTarget.y) + PI;
|
float fAngleTarget = CGeneral::GetATanOfXY(vecToTarget.x, vecToTarget.y) + PI;
|
||||||
if (pHeli->m_fHeliOrientation >= 0.0f)
|
if (pHeli->m_fHeliOrientation >= 0.0f)
|
||||||
fAngleTarget = pHeli->m_fHeliOrientation;
|
fAngleTarget = pHeli->m_fHeliOrientation;
|
||||||
|
fAngleTarget -= pHeli->m_fOrientation;
|
||||||
while (fAngleTarget < -PI)
|
while (fAngleTarget < -PI)
|
||||||
fAngleTarget += TWOPI;
|
fAngleTarget += TWOPI;
|
||||||
while (fAngleTarget > PI)
|
while (fAngleTarget > PI)
|
||||||
@ -2710,9 +2711,9 @@ void CCarCtrl::SteerAIHeliTowardsTargetCoors(CAutomobile* pHeli)
|
|||||||
if (Abs(fAngleTarget) <= 0.4f)
|
if (Abs(fAngleTarget) <= 0.4f)
|
||||||
ZTurnSpeedTarget = 0.0f;
|
ZTurnSpeedTarget = 0.0f;
|
||||||
else if (fAngleTarget < 0.0f)
|
else if (fAngleTarget < 0.0f)
|
||||||
ZTurnSpeedTarget = 0.03f;
|
|
||||||
else
|
|
||||||
ZTurnSpeedTarget = -0.03f;
|
ZTurnSpeedTarget = -0.03f;
|
||||||
|
else
|
||||||
|
ZTurnSpeedTarget = 0.03f;
|
||||||
}
|
}
|
||||||
float ZTurnSpeedChangeTarget = ZTurnSpeedTarget - pHeli->GetTurnSpeed().z;
|
float ZTurnSpeedChangeTarget = ZTurnSpeedTarget - pHeli->GetTurnSpeed().z;
|
||||||
float ZTurnSpeedLimit = 0.0002f * CTimer::GetTimeStep();
|
float ZTurnSpeedLimit = 0.0002f * CTimer::GetTimeStep();
|
||||||
@ -2729,7 +2730,7 @@ void CCarCtrl::SteerAIHeliTowardsTargetCoors(CAutomobile* pHeli)
|
|||||||
else
|
else
|
||||||
up = CVector(3.0f * pHeli->GetMoveSpeed().x, 3.0f * pHeli->GetMoveSpeed().y, 1.0f);
|
up = CVector(3.0f * pHeli->GetMoveSpeed().x, 3.0f * pHeli->GetMoveSpeed().y, 1.0f);
|
||||||
up.Normalise();
|
up.Normalise();
|
||||||
CVector forward(Sin(pHeli->m_fOrientation), Cos(pHeli->m_fOrientation), 0.0f);
|
CVector forward(Cos(pHeli->m_fOrientation), Sin(pHeli->m_fOrientation), 0.0f);
|
||||||
CVector right = CrossProduct(up, forward);
|
CVector right = CrossProduct(up, forward);
|
||||||
forward = CrossProduct(up, right);
|
forward = CrossProduct(up, right);
|
||||||
pHeli->GetMatrix().GetRight() = right;
|
pHeli->GetMatrix().GetRight() = right;
|
||||||
|
@ -5566,7 +5566,7 @@ CAutomobile::TellHeliToGoToCoors(float x, float y, float z, uint8 speed)
|
|||||||
SetStatus(STATUS_PHYSICS);
|
SetStatus(STATUS_PHYSICS);
|
||||||
|
|
||||||
if(m_fOrientation == 0.0f){
|
if(m_fOrientation == 0.0f){
|
||||||
m_fOrientation = CGeneral::GetATanOfXY(GetForward().x, GetForward().y) + TWOPI;
|
m_fOrientation = CGeneral::GetATanOfXY(GetForward().x, GetForward().y) + PI;
|
||||||
while(m_fOrientation > TWOPI) m_fOrientation -= TWOPI;
|
while(m_fOrientation > TWOPI) m_fOrientation -= TWOPI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user