So this is what I am doing. What can I improve?
//AIMelee.cpp
void AIMelee::FixedUpdate(float timeStep)
{
CrowdAgent* agent = node_->GetComponent<CrowdAgent>();
if (health <= 0 && dead_ == false)
{
PlaySound("Sounds/death_mjr.ogg",1.5f,50.0f,70.0f);
idle->PlayExclusive("Models/hunter_combat_landing_dead.ani", 0, false, 0.3f); .
if (node_->HasComponent<CrowdAgent>())
{
agent->Remove();
}
shape->SetCapsule(10.0f, 5.0f, Vector3(0.0f, 5.0f, 0.0f));
body->SetMass(0);
dead_ = true;
}
// This is our check to see if player is within radius to attack
boundingSphere();
}
// AIMelee.h
/// Handle scene update. Called by LogicComponent base class.
void Update(float timeStep)
{
elapsedTime_ += timeStep;
// Disappear when duration expired
if (duration_ >= 0 && dead_ == true)
{
duration_ -= timeStep;
if (duration_ <= 0)
{
node_->Remove();
}
}
if (oktoMelee_ == true)
{
// If melee is true from boundingSphere();
melee();
}
}
//AIMelee.cpp
void AIMelee::melee()
{
debug = scene_->GetComponent<DebugRenderer>();
CollisionShape* shape_ = handboneNode->CreateComponent<CollisionShape>();
shape_->SetCapsule(2.0f, 2.0f, Vector3::ZERO, Quaternion::IDENTITY);
PhysicsRaycastResult raycResult;
auto* physicsWorld = scene_->GetComponent<PhysicsWorld>();
const Vector3 start = handboneNode->GetWorldPosition();
const Vector3 end = start + (Vector3::FORWARD * 100.0f);
idle->Play("Models/hunter_combat_melee%1.ani", 0, false, 0.2f);
physicsWorld->ConvexCast(raycResult, shape_, start, Quaternion::IDENTITY, end, Quaternion::IDENTITY);
RigidBody* resultBody{ raycResult.body_ };
Character* _Node;
int damage = 15;
if (resultBody)
{
Node* resultNode{ resultBody->GetNode() };
if (_Node = resultNode->GetDerivedComponent<Character>())
{
_Node->setHealth(_Node->getHealth() - damage);
resultBody->ApplyImpulse(Vector3(1.0f, 1.0f, 1.0f)* 1.0f);
}
}
}