Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. void EffectSpawnerComponent::SpawnEffect(AZ::Vector3 pos, AZ::Vector3 hit_normal, EffectToSpawn effect)
  2. {
  3.     AZStd::shared_ptr<AZ::Entity> entity = AZStd::make_shared<AZ::Entity>("SpawnedEffect");
  4.  
  5.     // Before entity activation create all necessary components
  6.     AzFramework::TransformComponent* transform = azdynamic_cast<AzFramework::TransformComponent*>(entity->CreateComponent(AZ::TransformComponentTypeId));
  7.     if (transform)
  8.     {
  9.         AZ::Vector3 pos = m_entity->GetTransform()->GetWorldTranslation();
  10.         AZ::TransformConfig conf;
  11.         conf.m_isStatic = false;
  12.         conf.m_worldTransform = AZ::Transform::CreateTranslation(pos);
  13.         conf.m_netSyncEnabled = false;
  14.         conf.m_parentId = m_entity->GetId();
  15.         conf.m_parentActivationTransformMode = AZ::TransformConfig::ParentActivationTransformMode::MaintainOriginalRelativeTransform;
  16.         conf.m_interpolatePosition = AZ::InterpolationMode::NoInterpolation;
  17.         conf.m_interpolatePosition = AZ::InterpolationMode::NoInterpolation;
  18.  
  19.         transform->SetConfiguration(conf);
  20.     }
  21.  
  22.     LmbrCentral::ParticleComponent* emit = azdynamic_cast<LmbrCentral::ParticleComponent*>(entity->CreateComponent(AZ::AzTypeInfo<LmbrCentral::ParticleComponent>::Uuid()));
  23.     if (emit)
  24.     {
  25.         using namespace LmbrCentral;
  26.  
  27.         AZStd::string name = "MyParticles.DroidHit";
  28.        
  29.         LmbrCentral::ParticleEmitterSettings emitterSettings;
  30.         emitterSettings.m_targetEntity = entity->GetId();
  31.         emitterSettings.m_notAttached = false;
  32.         emitterSettings.m_visible = true;
  33.        
  34.         ParticleComponentRequestBus::Event(entity->GetId(), &ParticleComponentRequestBus::Events::SetupEmitter, name, emitterSettings);
  35.         ParticleComponentRequestBus::Event(entity->GetId(), &ParticleComponentRequestBus::Events::Show);
  36.  
  37.         emit->Init();
  38.         emit->Activate();
  39.     }
  40.  
  41.     // We can't add component while the entity is active, so activate it after adding components!
  42.     entity->Init();
  43.     entity->Activate();
  44.    
  45.     // Owner Entity(parent entity) subscribs for the child's EntityBus events (activate/deactivate)
  46.     //AZ::EntityBus::MultiHandler::BusConnect(entity->GetId());
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement