Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. //Thats bound on E key, it is called when E is pressed, but the location is always 0,0,0 and rotation vertical, but as you can see it should be random
  2.  
  3. void AMyProjectCharacter::SpawnSomeThing(){
  4.     FActorSpawnParameters SpawnParams;
  5.     SpawnParams.Owner = this;
  6.     SpawnParams.Instigator = Instigator;
  7.     FVector SpawnLocation = FVector(-850.0f, 0.0f, 1000.0f);
  8.     FRotator SpawnRotation;
  9.     SpawnRotation.Yaw = FMath::FRand() * 360.f;
  10.     SpawnRotation.Pitch = FMath::FRand() * 360.f;
  11.     SpawnRotation.Roll = FMath::FRand() * 360.f;
  12.     GetWorld()->SpawnActor<ASomeThing>(ASomeThing::StaticClass(), SpawnLocation, SpawnRotation, SpawnParams);
  13. }
  14.  
  15. //SomeThing.h
  16.  
  17. UCLASS()
  18. class MYPROJECT_API ASomeThing : public AActor
  19. {
  20.     GENERATED_BODY()
  21.    
  22. public:
  23.  
  24.     USphereComponent* CollisionComponent;
  25.     UStaticMeshComponent* Mesh;
  26.  
  27.     // Sets default values for this actor's properties
  28.     ASomeThing(const FObjectInitializer &ObjectInitializer);
  29.  
  30.     // Called when the game starts or when spawned
  31.     virtual void BeginPlay() override;
  32.    
  33.     // Called every frame
  34.     virtual void Tick( float DeltaSeconds ) override;
  35.  
  36.    
  37.    
  38. };
  39.  
  40. //SomeThing.cpp
  41.  
  42. // Fill out your copyright notice in the Description page of Project Settings.
  43.  
  44. #include "MyProject.h"
  45. #include "SomeThing.h"
  46.  
  47.  
  48. // Sets default values
  49. ASomeThing::ASomeThing(const FObjectInitializer &ObjectInitializer) :Super(ObjectInitializer)
  50. {
  51.  
  52.     CollisionComponent = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("CollisionComponent"));
  53.     RootComponent = CollisionComponent;
  54.  
  55.     Mesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PickupMesh"));
  56.  
  57.     static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMesh(TEXT("StaticMesh'/Game/ThirdPerson/Meshes/Ramp_StaticMesh'"));
  58.  
  59.     static ConstructorHelpers::FObjectFinder<UMaterial> Material_Blue(TEXT("MaterialInstanceConstant'/Game/StarterContent/Materials/M_Water_Lake.M_Water_Lake'"));
  60.    
  61.     //Turn physics on fpr the static mesh
  62.     Mesh->SetSimulatePhysics(true);
  63.     Mesh->SetStaticMesh(StaticMesh.Object);
  64.     Mesh->SetMaterial(0, Material_Blue.Object);
  65.  
  66.     Mesh->AttachTo(RootComponent);
  67.  
  68.     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  69.     PrimaryActorTick.bCanEverTick = true;
  70.  
  71. }
  72.  
  73. // Called when the game starts or when spawned
  74. void ASomeThing::BeginPlay()
  75. {
  76.     Super::BeginPlay();
  77.    
  78. }
  79.  
  80. // Called every frame
  81. void ASomeThing::Tick( float DeltaTime )
  82. {
  83.     Super::Tick( DeltaTime );
  84.    
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement