void Player::Raycast(const GameContext& gameContext) { GameScene* scene = GetScene(); XMFLOAT3 pos = GetTransform()->GetPosition(); XMFLOAT3 fw = GetTransform()->GetForward(); PxVec3 rayOrigin(pos.x,pos.y + 1.f,pos.z), rayDirection(fw.x,fw.y,fw.z); rayOrigin.x += fw.x * 2.5f; rayOrigin.z += fw.z * 2.5f; const PxU32 bufSize = 20; PxRaycastHit hit[bufSize]; PxRaycastBuffer buf(hit, bufSize); // [out] Blocking and touching hits will be stored here if(scene->GetPhysxProxy()->Raycast(rayOrigin, rayDirection, 5000, buf)) { for(PxU32 i = 0; i < buf.nbTouches; ++i) { BaseComponent* component = static_cast<BaseComponent*>(buf.touches[i].actor->userData); GameObject* go = component->GetGameObject(); string name = go->GetName(); cout << "RAYCAST OBJECT: " << name << endl; if(name == "Enemy") { Enemy* enemy = reinterpret_cast<Enemy*>(go); int dmg = 12.5f; enemy->Damage(dmg); } } PxVec3 vel = rayDirection * 1000; auto laser = new Laser(XMFLOAT3(vel.x, vel.y, vel.z)); AddChild(laser); } }