Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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
- void AMyProjectCharacter::SpawnSomeThing(){
- FActorSpawnParameters SpawnParams;
- SpawnParams.Owner = this;
- SpawnParams.Instigator = Instigator;
- FVector SpawnLocation = FVector(-850.0f, 0.0f, 1000.0f);
- FRotator SpawnRotation;
- SpawnRotation.Yaw = FMath::FRand() * 360.f;
- SpawnRotation.Pitch = FMath::FRand() * 360.f;
- SpawnRotation.Roll = FMath::FRand() * 360.f;
- GetWorld()->SpawnActor<ASomeThing>(ASomeThing::StaticClass(), SpawnLocation, SpawnRotation, SpawnParams);
- }
- //SomeThing.h
- UCLASS()
- class MYPROJECT_API ASomeThing : public AActor
- {
- GENERATED_BODY()
- public:
- USphereComponent* CollisionComponent;
- UStaticMeshComponent* Mesh;
- // Sets default values for this actor's properties
- ASomeThing(const FObjectInitializer &ObjectInitializer);
- // Called when the game starts or when spawned
- virtual void BeginPlay() override;
- // Called every frame
- virtual void Tick( float DeltaSeconds ) override;
- };
- //SomeThing.cpp
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "MyProject.h"
- #include "SomeThing.h"
- // Sets default values
- ASomeThing::ASomeThing(const FObjectInitializer &ObjectInitializer) :Super(ObjectInitializer)
- {
- CollisionComponent = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("CollisionComponent"));
- RootComponent = CollisionComponent;
- Mesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PickupMesh"));
- static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMesh(TEXT("StaticMesh'/Game/ThirdPerson/Meshes/Ramp_StaticMesh'"));
- static ConstructorHelpers::FObjectFinder<UMaterial> Material_Blue(TEXT("MaterialInstanceConstant'/Game/StarterContent/Materials/M_Water_Lake.M_Water_Lake'"));
- //Turn physics on fpr the static mesh
- Mesh->SetSimulatePhysics(true);
- Mesh->SetStaticMesh(StaticMesh.Object);
- Mesh->SetMaterial(0, Material_Blue.Object);
- Mesh->AttachTo(RootComponent);
- // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
- PrimaryActorTick.bCanEverTick = true;
- }
- // Called when the game starts or when spawned
- void ASomeThing::BeginPlay()
- {
- Super::BeginPlay();
- }
- // Called every frame
- void ASomeThing::Tick( float DeltaTime )
- {
- Super::Tick( DeltaTime );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement