My bullet (not bullet physics) working ok when bullet hit box. But I have above box billboard to show HP and if bullet hit billboard and then my box, it stop working and bullet is going away and don’t care about my box.
It even doesnt work when bullet fly throught billboard on scene which have not any connections with my object.
I have no clue where can be problem.
This is code how I create object inside GameApp
Node* boxNode_ = scene_->CreateChild("Box");
boxNode_->SetPosition(Vector3(x, -3, z));
boxNode_->SetScale(Vector3(2, 2, 2));
MyCube * mc = boxNode_->CreateComponent<MyCube>();
mc->CreateObject(boxNode_, cache);
My custom object
void Urho3D::MyCube::CreateObject(Node * node, ResourceCache * cache)
{
m_node = node;
Node * node_model = m_node->CreateChild("MyCube");
m_model = node_model->CreateComponent<StaticModel>();
// ...
// billboard
// ...
m_node_billboard = m_node->CreateChild("HealthBar");
m_node_billboard->SetPosition(Vector3(0, 0.8, 0));
m_bs = m_node_billboard->CreateComponent<BillboardSet>();
m_bs->SetNumBillboards(1);
// ...
m_bs->Commit();
// ...
}
And here is my bullet code
void Urho3D::MyBullet::mf_Update(StringHash eventType, VariantMap & eventData)
{
if (myBulletNode != nullptr && myBulletScene != nullptr && m_STOP == false)
{
Vector3 hitPos;
Drawable* hitDrawable;
float timeStep = eventData[Update::P_TIMESTEP].GetFloat();
if (Raycast((float)(m_Speed*timeStep), hitPos, hitDrawable))
{
Node* hitNode = hitDrawable->GetNode();
if (hitNode->GetName() == "MyCube")
{
MyCube * myCube = hitNode->GetParentComponent<MyCube>();
if (myCube != nullptr)
{
myCube->mf_ISetDamage(m_damage);
m_STOP = true;
}
}
}
myBulletNode->Translate(Vector3(0, 0, 1) * m_Speed * timeStep);
}
if (m_STOP == true)
{
myBulletNode->Remove();
}
}
bool Urho3D::MyBullet::Raycast(float maxDistance, Vector3 & hitPos, Drawable *& object)
{
object = 0;
if (myBulletNode == nullptr || myBulletScene == nullptr)
return false;
Graphics * graphics = GetSubsystem<Graphics>();
Ray ray(myBulletNode->GetPosition(), myBulletNode->GetDirection());
PODVector<RayQueryResult> results;
RayOctreeQuery query(results, ray, RAY_TRIANGLE, maxDistance, DRAWABLE_GEOMETRY);
myBulletScene->GetComponent<Octree>()->RaycastSingle(query);
if (results.Size())
{
RayQueryResult& result = results[0];
hitPos = result.position_;
object = result.drawable_;
return true;
}
return false;
}