void AMyProjectBlockGrid::BeginPlay()
{
	Super::BeginPlay();

	// Number of blocks
	const int32 NumBlocks = Size * Size;

	// Loop to spawn each block
	for(int32 BlockIndex=0; BlockIndex<NumBlocks; BlockIndex++)
	{
		const float XOffset = (BlockIndex/Size) * BlockSpacing; // Divide by dimension
		const float YOffset = (BlockIndex%Size) * BlockSpacing; // Modulo gives remainder

		// Make postion vector, offset from Grid location
		const FVector BlockLocation = FVector(XOffset, YOffset, 0.f) + GetActorLocation();

		// Spawn a block
		AMyProjectBlock* NewBlock = GetWorld()->SpawnActor<AMyProjectBlock>(BlockLocation, FRotator(0,0,0));

		// Tell the block about its owner
		if(NewBlock != NULL)
		{
			NewBlock->OwningGrid = this;
		}
	}
}
示例#2
0
void FSimpleHMD::SetupView(FSceneViewFamily& InViewFamily, FSceneView& InView)
{
	InView.BaseHmdOrientation = FQuat(FRotator(0.0f,0.0f,0.0f));
	InView.BaseHmdLocation = FVector(0.f);
//	WorldToMetersScale = InView.WorldToMetersScale;
	InViewFamily.bUseSeparateRenderTarget = false;
}
FRotator UKismetMathLibrary::ComposeRotators(FRotator A, FRotator B)
{
	FQuat AQuat = FQuat(A);
	FQuat BQuat = FQuat(B);

	return FRotator(BQuat*AQuat);
}
示例#4
0
// Called every frame
void APilotPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	//InputComponent->GetAxisValue("HandX");
	Hand_move_dirvec.X = 3;

	if (InputComponent)
	{
		//InputComponent->GetAxisValue("HandX");
		Hand_move_dirvec.X = InputComponent->GetAxisValue("HandX");
		Hand_move_dirvec.Y = InputComponent->GetAxisValue("HandY");
		Hand_move_dirvec.Z = InputComponent->GetAxisValue("HandZ");
		InputComponent->GetAxisValue("RightGrasp") > 0 ? RightHand->MakeGrabAvailable() : RightHand->MakeGrabUnable();
		InputComponent->GetAxisValue("LeftGrasp") > 0 ? LeftHand->MakeGrabAvailable() : LeftHand->MakeGrabUnable();
		InputComponent->GetAxisValue("LeftSecondaryGrasp") > 0 ? LeftHand->MakeSecondaryGraspAvailable() : LeftHand->MakeSecondaryGraspUnable();
		InputComponent->GetAxisValue("RightSecondaryGrasp") > 0 ? RightHand->MakeSecondaryGraspAvailable() : RightHand->MakeSecondaryGraspUnable();
	}
	else
		Hand_move_dirvec.X = 30000;
	//Hand_move_dirvec /= (float)Hand_move_dirvec.Size();
	RightArm->SetRelativeLocation(FirstPersonCameraComponent->RelativeLocation + RelativeArmposition);
	LeftArm->SetRelativeLocation(FirstPersonCameraComponent->RelativeLocation + RelativeArmposition);

	LeftRealHandScene->AddLocalOffset(FVector(InputComponent->GetAxisValue("LeftHandX"), InputComponent->GetAxisValue("LeftHandY"), InputComponent->GetAxisValue("LeftHandZ")));
	RightRealHandScene->AddLocalOffset(Hand_move_dirvec * 1);
	FirstPersonCameraComponent->AddRelativeRotation(FRotator(-InputComponent->GetAxisValue("YaxisLook"), InputComponent->GetAxisValue("XaxisLook"), 0));
}
void ABrainNormalInteractiveObject::Tick(float deltaTime)
{
	Super::Tick(deltaTime);

	if (_canBeRotate)
	{
		_currentRotation += (_deltaRotation * (deltaTime / _animDuration));
		_durationRotation += deltaTime;
		if (_durationRotation > _animDuration)
		{
			_currentRotation = _targetRotation;
			_deltaRotation = FRotator(0, 0, 0); // Annulation du deltaRotation
		}

		SetActorRotation(_currentRotation);
	}

	if (_canBeTranslate)
	{
		_currentTranslation += (_deltaTranslation * deltaTime / _animDuration);
		_durationTranslation += deltaTime;
		if (_durationTranslation > _animDuration)
		{
			_currentTranslation = _targetTranslation;
			_deltaTranslation = FVector(0, 0, 0); // Annulation du deltaSize
		}

		SetActorLocation(_currentTranslation,true);
	}

	if (_canBeScale)
	{
		_currentScale += (_deltaScale * deltaTime / _animDuration);
		_durationScale += deltaTime;
		if (_durationScale > _animDuration)
		{
			_currentScale = _targetScale;
			_deltaScale = FVector(0,0,0); // Annulation du deltaSize
		}

		SetActorScale3D(_currentScale);
	}

	if (_canBeShear)
	{
		_currentShearFirstAxis += (_deltaShearFirstAxis * deltaTime / _animDuration);
		_currentShearSecondAxis += (_deltaShearSecondAxis * deltaTime / _animDuration);
		_durationShear += deltaTime;
		if (_durationShear > _animDuration)
		{
			_currentShearFirstAxis = _targetShearFirstAxis;
			_currentShearSecondAxis = _targetShearSecondAxis;
			_deltaShearFirstAxis = 0;
			_deltaShearSecondAxis = 0;
		}

		FTransform sTrans = FTransform(Shear(_currentShearFirstAxis, _currentShearSecondAxis));
		SetActorTransform(sTrans*_cachedTransform);
	}
}
示例#6
0
// Called every frame
void AGem::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );

	CollectionParticles->SetColorParameter("ParticleColor", GemColor);
	CollectionParticles->SetRelativeLocation(FVector::ZeroVector);
	CollectionParticles->SetWorldRotation(FRotator::ZeroRotator);
	CollectionParticles->SetWorldScale3D(FVector(1.0f, 1.0f, 1.0f));
	//CollectionParticles->UpdateInstances();
	FVector loc = GetActorLocation();
	loc = FVector(0.0f, 0.0f, 10.0f*DeltaTime*FMath::Cos(curTime*PI));

	if (Player != nullptr) {
		CollectionParticles->SetVectorParameter("PlayerPosition", 1.0f*(Player->GetActorLocation()-GetActorLocation()));
		CollectionParticles->SetVectorParameter("PlayerSize1", Player->GetActorLocation() + (DeltaTime / 0.016f)*FVector(-45.0f, -45.0f, -45.0f));
		CollectionParticles->SetVectorParameter("PlayerSize2", Player->GetActorLocation() + (DeltaTime / 0.016f)*FVector(45.0f, 45.0f, 45.0f));
		CollectionParticles->SetFloatParameter("Strength", (1.0f/DeltaTime)*FMath::Clamp(GetWorldTimerManager().GetTimerElapsed(PostCollectionTimer) / 2.0f, 0.0f, 1.0f)*FMath::Clamp(GetWorldTimerManager().GetTimerElapsed(PostCollectionTimer) / 2.0f, 0.0f, 1.0f));
	} else {
		SetActorLocation(GetActorLocation() + loc);
		GemModel->AddWorldRotation(FRotator(0.0f, 60.0f*DeltaTime, 0.0f));
	}

	// Eliot made me put this here.
	if (GetWorldTimerManager().GetTimerElapsed(PostCollectionTimer) != -1.0f) {
		gemmat->SetScalarParameterValue("Break", 20.0f*GetWorldTimerManager().GetTimerElapsed(PostCollectionTimer));
	}

	curTime += DeltaTime;
}
ARTJamCharacter::ARTJamCharacter()
{
	// Set size for collision capsule
	GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
	GetCapsuleComponent()->OnComponentHit.AddDynamic(this, &ARTJamCharacter::OnHit);

	// Don't rotate when the controller rotates.
	bUseControllerRotationPitch = false;
	bUseControllerRotationYaw = false;
	bUseControllerRotationRoll = false;

	// Configure character movement
	GetCharacterMovement()->bOrientRotationToMovement = true; // Face in the direction we are moving..
	GetCharacterMovement()->RotationRate = FRotator(0.0f, 720.0f, 0.0f); // ...at this rotation rate
	GetCharacterMovement()->GravityScale = 2.f;
	GetCharacterMovement()->AirControl = 0.80f;
	GetCharacterMovement()->JumpZVelocity = 1000.f;
	GetCharacterMovement()->GroundFriction = 3.f;
	GetCharacterMovement()->MaxWalkSpeed = 600.f;
	GetCharacterMovement()->MaxFlySpeed = 600.f;

	// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character) 
	// are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++)

	bIsDead = false;

	NormalImpulse = 800.f;
	MaxImpulse = 1000.f;
	ForceLength.Z = NormalImpulse;
}
示例#8
0
AShipPawn::AShipPawn()
{
	PrimaryActorTick.bCanEverTick = true;

	static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereMesh(TEXT("/Game/Assets/Ships/DroneShip"));
	MeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComponent"));
	MeshComponent->SetCollisionProfileName(UCollisionProfile::Pawn_ProfileName);
	MeshComponent->SetStaticMesh(SphereMesh.Object);
	MeshComponent->SetMobility(EComponentMobility::Movable);
	MeshComponent->SetSimulatePhysics(true);
	MeshComponent->BodyInstance.bLockZTranslation = true;
	MeshComponent->SetEnableGravity(false);
	MeshComponent->SetLinearDamping(ShipLinearDamping);
	MeshComponent->SetAngularDamping(ShipAngularDamping);
	MeshComponent->BodyInstance.bLockXRotation = true;
	MeshComponent->BodyInstance.bLockYRotation = true;


	RootComponent = MeshComponent;


	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
	CameraBoom->AttachTo(RootComponent);
	CameraBoom->bAbsoluteRotation = true;
	CameraBoom->TargetArmLength = 20000.f;
	CameraBoom->RelativeRotation = FRotator(-80.f, 0.f, 0.f);
	CameraBoom->bDoCollisionTest = false;

	CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
	CameraComponent->AttachTo(CameraBoom, USpringArmComponent::SocketName);
	CameraComponent->bUsePawnControlRotation = false;
}
ACapTheBrainCharacter::ACapTheBrainCharacter(const class FObjectInitializer& PCIP)
	: Super(PCIP)
{
	buff = 100;
	buffTimer = 0;
	buffDelay = 2;
	score = 0;
	firstUpdate = true;
	// Set size for collision capsule
	GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);

	// set our turn rates for input
	BaseTurnRate = 45.f;
	BaseLookUpRate = 45.f;

	// Don't rotate when the controller rotates. Let that just affect the camera.
	bUseControllerRotationPitch = false;
	bUseControllerRotationYaw = false;
	bUseControllerRotationRoll = false;

	// Configure character movement
	GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...	
	GetCharacterMovement()->RotationRate = FRotator(0.0f, 540.0f, 0.0f); // ...at this rotation rate
	GetCharacterMovement()->JumpZVelocity = 200.f;
	GetCharacterMovement()->AirControl = 0.2f;

	// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character) 
	// are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++) 
}
示例#10
0
//========================================================================
void AHexEditorActor::UpdateBarrierPlacing()
{
	if (m_CurrentBarrier)
	{
		check(m_InputType == InputMode::Barriers);
		
		Raycast<AHexTileActor>(this,
			[&](auto& resultActor, auto& traceResult) 
			{
				auto& coords = resultActor->GetCoordinates();
				auto tilePos = m_Grid.GetPosition(coords);
				auto toHit = traceResult.ImpactPoint - tilePos;
				auto nId = GetNeighborId(toHit);
				auto neighborRelativeCoordinates = T_HexGrid::HorizontalNeighborIndexes[nId];

				auto pos = m_Grid.GetPositionBetweenTiles(coords, coords + neighborRelativeCoordinates);
				m_CurrentBarrier->SetActorLocation(pos);
				m_CurrentBarrier->SetActorRotation(FRotator(0, 60 * -(int)nId, 0));

				m_CurrentBarrier->SetOwningTileBeforePlace(resultActor, nId);
			},
			[&]()
			{
				m_CurrentBarrier->SetOwningTileBeforePlace(nullptr);
			});
	}
}
示例#11
0
// Sets default values
ADog::ADog()
{
 	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
	AutoPossessPlayer = EAutoReceiveInput::Player0;

	CollisionSphere =
		CreateDefaultSubobject<USphereComponent>(TEXT("CollisionSphere"));
	CollisionSphere->SetCollisionObjectType(ECollisionChannel::ECC_Pawn);
	//Might want to tweak this in the editor depending on the size of the static mesh
	CollisionSphere->InitSphereRadius(10.0f);
	CollisionSphere->SetCollisionProfileName(TEXT("Pawn"));
	RootComponent = CollisionSphere;

	MovementComponent = CreateDefaultSubobject<UFloatingPawnMovement>("MovementComponent");
	MovementComponent->SetUpdatedComponent(RootComponent);

	StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
	StaticMesh->AttachTo(RootComponent);

	OtherMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("OtherMesh"));
	OtherMesh->AttachTo(RootComponent);
	OtherMesh->SetVisibility(false);

	Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
	Camera->AttachTo(RootComponent);
	Camera->SetRelativeLocation(FVector(-100.0f, 0.0f, 200.0f));
	Camera->SetRelativeRotation(FRotator(-60.0f, 0.0f, 0.0f));

}
示例#12
0
// Sets default values
AMyPawn::AMyPawn()
{
	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	//Set this pawn to be controlled by the lowest numbered player
	AutoPossessPlayer = EAutoReceiveInput::Player0;

	//Create a dummy root component to attach things to.
	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
	//create a camera and a visible object
	UCameraComponent* OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("OurCamera"));
	OurVisibleComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("OurVisibleComponent"));

	//attach our camera and visible object to the root
	OurCamera->AttachTo(RootComponent);
	(*OurVisibleComponent).AttachTo(RootComponent);

	//offset camera
	OurCamera->SetRelativeLocation(FVector(-250, 0, 250));

	//rotate camera
	OurCamera->SetRelativeRotation(FRotator(-45, 0, 0));
	InitLocation = GetActorLocation();
}
FCreatureAnimStoreEditorViewportClient::FCreatureAnimStoreEditorViewportClient(const TWeakPtr<class SEditorViewport>& InEditorViewportWidget /*= nullptr*/, UCreatureAnimationClipsStore* EditingAnimStore)
    :FEditorViewportClient(nullptr, &OwnerScene, InEditorViewportWidget)
    , EditingStore(EditingAnimStore)
{
    PreviewScene = &OwnerScene;
    ((FAssetEditorModeManager*)ModeTools)->SetPreviewScene(PreviewScene);
    DrawHelper.bDrawGrid = true;
    DrawHelper.bDrawPivot = true;

    /*SetViewLocation(FVector(0, 30, 0));
    SetLookAtLocation(FVector(0, -30, 0));*/


    SetRealtime(true);
    //向PreviewScene添加Component
    EditingCreatureMesh = NewObject<UCreatureMeshComponent>();
    //设置CreatureMesh组件
    SetUpEditingCreatureMesh();
    PreviewScene->AddComponent(EditingCreatureMesh, FTransform::Identity);
    EditingCreatureMesh->SetRelativeRotation(FRotator(0, 90, 0));

    //设置Camera
    SetUpCamera();

    if (EditingStore->ClipList.Num()!=0)
    {
        //默认播放第一个Clip
        EditingCreatureMesh->SetBluePrintActiveCollectionClip_Name(EditingStore->ClipList[0].ClipName);
    }

}
示例#14
0
// Sets default values
ASceneBarricades::ASceneBarricades()
{
 	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

   struct FConstructorStatics
   {
      ConstructorHelpers::FObjectFinderOptional<UStaticMesh> barricadeShape;
      ConstructorHelpers::FObjectFinderOptional<UMaterialInstance> barricadeMaterial;
      FConstructorStatics()
         : barricadeShape(TEXT("/Game/MapProps/blockade.blockade"))
         , barricadeMaterial(TEXT("Material'/Game/MapProps/cementLight.cementLight'"))
      {
      }
   };
   static FConstructorStatics ConstructorStatics;

   // Create dummy root scene component
   //DummyRoot = CreateDefaultSubobject<USceneComponent>(TEXT("Dummy0"));
   //RootComponent = DummyRoot;

   ItemBasicMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("item_shape"));
   // Create random mesh component
   ItemBasicMesh->SetStaticMesh(ConstructorStatics.barricadeShape.Get());
   ItemBasicMesh->SetMaterial(0, ConstructorStatics.barricadeMaterial.Get());
   ItemBasicMesh->SetRelativeScale3D(FVector(0.2f,0.2f,0.2f));
   ItemBasicMesh->SetRelativeLocation(FVector(0.f,0.f,0.f));
   ItemBasicMesh->SetRelativeRotation(FRotator(0.f, 0.f, 0.f));
   //ItemBasicMesh->AttachTo(DummyRoot);

   health = 3;

   this->OnActorHit.AddDynamic(this, &ASceneBarricades::onHit);
}
示例#15
0
FRotator CombineRotators(FRotator A, FRotator B)
{
    FQuat AQuat = FQuat(A);
    FQuat BQuat = FQuat(B);

    return FRotator(BQuat*AQuat);
}
示例#16
0
void UTankTurret::Rotate(float RelativeSpeed)
{
	RelativeSpeed = FMath::Clamp<float>(RelativeSpeed, -1, +1);
	auto RotationChange = RelativeSpeed * MaxDegreesPerSecond * GetWorld()->DeltaTimeSeconds;
	auto Rotation = RelativeRotation.Yaw + RotationChange;
	SetRelativeRotation(FRotator(0, Rotation, 0));
}
示例#17
0
//Conversion - use find and replace to change behavior, no scaling version is typically used for orientations
FVector convertLeapToUE(Leap::Vector leapVector)
{
    //Convert Axis
    FVector vect = FVector(-leapVector.z, leapVector.x, leapVector.y);

    //Hmd orientation adjustment
    if (LeapShouldAdjustForFacing)
    {
        FRotator rotation = FRotator(90.f, 0.f, 180.f);
        vect = FQuat(rotation).RotateVector(vect);

        if (LeapShouldAdjustRotationForHMD)
        {
            if (GEngine->HMDDevice.IsValid())
            {
                FQuat orientationQuat;
                FVector position;
                GEngine->HMDDevice->GetCurrentOrientationAndPosition(orientationQuat, position);
                vect = orientationQuat.RotateVector(vect);
            }
        }
    }

    return vect;
}
// Sets default values
APawnWithCamera::APawnWithCamera()
{
 	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
	
	//Create this actors components
	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
	OurCameraSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArm"));
	OurCameraSpringArm->AttachTo(RootComponent);
	OurCameraSpringArm->SetRelativeLocationAndRotation(FVector(0.0f, 0.0f, 50.0f), FRotator(-60.0f, 0.0f, 0.0f));
	OurCameraSpringArm->TargetArmLength = 400.f;
	OurCameraSpringArm->bEnableCameraLag = true;
	OurCameraSpringArm->CameraLagSpeed = 3.0f;

	//create and attach the camera
	OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("GameCamera"));
	OurCamera->AttachTo(OurCameraSpringArm, USpringArmComponent::SocketName);

	//take control of the default player
	AutoPossessPlayer = EAutoReceiveInput::Player0;

	//default speed values
	ForwardSpeed = 300.0f;
	StrafeSpeed = 200.0f;
	//default look sensitivity
	LookSensitivityX = 2.0f;
	LookSensitivityY = 2.0f;
}
AMobileAgentSlickPawn::AMobileAgentSlickPawn()
{	
	static ConstructorHelpers::FObjectFinder<UStaticMesh> ShipMesh(TEXT("/Game/TwinStick/Meshes/TwinStickUFO.TwinStickUFO"));
	// Create the mesh component
	ShipMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ShipMesh"));
	RootComponent = ShipMeshComponent;
	ShipMeshComponent->SetCollisionProfileName(UCollisionProfile::Pawn_ProfileName);
	ShipMeshComponent->SetStaticMesh(ShipMesh.Object);
	

	// Create a camera boom...
	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
	CameraBoom->AttachTo(RootComponent);
	CameraBoom->bAbsoluteRotation = true; // Don't want arm to rotate when ship does
	CameraBoom->TargetArmLength = 1200.f;
	CameraBoom->RelativeRotation = FRotator(-90.f, 0.f, 0.f);
	CameraBoom->bDoCollisionTest = false; // Don't want to pull camera in when it collides with level

	// Create a camera...
	CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("TopDownCamera"));
	CameraComponent->AttachTo(CameraBoom, USpringArmComponent::SocketName);
	CameraComponent->bUsePawnControlRotation = false;	// Camera does not rotate relative to arm

	// Movement
	MoveSpeed = 1000.0f;
}
示例#20
0
void AMech_RPGCharacter::Tick(float DeltaTime) {
	Super::Tick(DeltaTime);
	if (!isDead) {
		GetCharacterMovement()->MaxWalkSpeed = speed * speedModifier;

		if (GetHealth() < GetMaxHealth()) {
			float regen = !inCombat ? GetMaxHealth() * 0.15 : healthRegen;
			health += regen * DeltaTime;

			GetFloatingStats()->UpdateHealthBar();

			if (GetCharacterStats() != nullptr) {
				GetCharacterStats()->UpdateHealthBar();
			}
		}

		if (stats->GetUserWidgetObject() != nullptr && stats->GetUserWidgetObject() != nullptr) {
			if (mIsChildOf(GetController(), AMech_RPGPlayerController::StaticClass()) && GetTopDownCamera() != nullptr) {
				UMiscLibrary::SetCameraRot(FRotator(-GetTopDownCamera()->GetComponentRotation().Pitch, UMiscLibrary::GetWidgetYaw(GetTopDownCamera()) + 90, 0));
				GetStats()->SetWorldRotation(UMiscLibrary::GetCameraRot());
			}
			else if (GetStats() != nullptr) {
				GetStats()->SetWorldRotation(UMiscLibrary::GetCameraRot());
			}
		}
	}

	CLAMP(health, GetMaxHealth(), 0);
}
示例#21
0
void FCameraManager::addRotationToViewportCamera(FRotator deltaRot)
{
	if (_viewportCamera)
	{
		_viewportCameraRotation += deltaRot;

		Vector3 aux = _viewportCameraRotation.toEuler();
		//Clamp pitch Pitch
		aux.x = Math::clamp(aux.x, _pitchRotationLimitMin, _pitchRotationLimitMax);

		//Set back yaw to 0 if it exceeds 360
		if (aux.y > 359.9f || aux.y < -359.9f)
		{
			aux.y = 0;
		}

		_viewportCameraRotation = FRotator(aux);

		_viewportCamera->setLocalRotation(_viewportCameraRotation.toQuaternion());
	}
	else
	{
		FLog(FLog::FAILURE, "There is no Viewport Camera set");
		assert(0);
	}
}
// Sets default values
APawnWithCamera::APawnWithCamera()
{
    
    //To create "Voyager" and for it to have collision, we must make a camera inside of a sphere
    //This way we can zip about the universe and not collide with planets/the sun
    PrimaryActorTick.bCanEverTick = true;
    
    // Our root component will be a sphere that reacts to physics
    USphereComponent* SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("RootComponent"));
    RootComponent = SphereComponent;
    SphereComponent->InitSphereRadius(100.0f);
    SphereComponent->SetCollisionProfileName(TEXT("Pawn"));
    
    OurCameraSpringArm=CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArm"));
    OurCameraSpringArm->AttachTo(RootComponent);
    OurCameraSpringArm->RelativeRotation = FRotator(-10.0f, 0.0f, 0.0f);
    OurCameraSpringArm->TargetArmLength = 0.0f;
    OurCameraSpringArm->bEnableCameraLag = false;
    OurCameraSpringArm->CameraLagSpeed = 0.0f;
        
    //Create camera and attach spring arm
    OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("GameCamera"));
    OurCamera->AttachTo(OurCameraSpringArm, USpringArmComponent::SocketName);
    
    // Create an instance of our movement component, and tell it to update our root component.
    OurMovementComponent = CreateDefaultSubobject<UVoyagerPawnMovementComponent>(TEXT("CustomMovementComponent"));
    OurMovementComponent->UpdatedComponent = RootComponent;
    
    //Take control of the default Player
    AutoPossessPlayer = EAutoReceiveInput::Player0;
    
    //Set bearing mode time to 2 (default) it is editable from the editor
    BearingTime = 2.0f;
    SphereVisualLocation = (FVector(0.0f, 0.0f, -40.0f));
}
void AActor::EditorApplyRotation(const FRotator& DeltaRotation, bool bAltDown, bool bShiftDown, bool bCtrlDown)
{
	if( RootComponent != NULL )
	{
		const FRotator Rot = RootComponent->GetAttachParent() != NULL ? GetActorRotation() : RootComponent->RelativeRotation;

		FRotator ActorRotWind, ActorRotRem;
		Rot.GetWindingAndRemainder(ActorRotWind, ActorRotRem);

		const FQuat ActorQ = ActorRotRem.Quaternion();
		const FQuat DeltaQ = DeltaRotation.Quaternion();
		const FQuat ResultQ = DeltaQ * ActorQ;
		const FRotator NewActorRotRem = FRotator( ResultQ );
		FRotator DeltaRot = NewActorRotRem - ActorRotRem;
		DeltaRot.Normalize();

		if( RootComponent->GetAttachParent() != NULL )
		{
			RootComponent->SetWorldRotation( Rot + DeltaRot );
		}
		else
		{
			// No attachment.  Directly set relative rotation (to support winding)
			RootComponent->SetRelativeRotation( Rot + DeltaRot );
		}
	}
	else
	{
		UE_LOG(LogActor, Warning, TEXT("WARNING: EditorApplyRotation %s has no root component"), *GetName() );
	}
}
示例#24
0
// Called every frame
void AEquipmentPickup::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
	t += DeltaTime;
	SetActorRelativeLocation(start + FMath::Sin(t*PI)*25.0f*FVector::UpVector);
	AddActorWorldRotation(FRotator(0.0f, DeltaTime*135.0f, 0.0f));
}
FRotator AGGJ16_Player::CalculateTargetRotation()
{
	float Yaw = FMath::RadiansToDegrees(FMath::Atan2(CurrentInputRotation.Y, CurrentInputRotation.X));
	SetActorRotation(FMath::Lerp(GetActorRotation(), FRotator(0.f, Yaw, 0.f), RotationAlpha));
	return GetActorRotation();

}
示例#26
0
AsbrProjectile::AsbrProjectile(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
	CollisionComponent = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("SphereComponent"));
	CollisionComponent->InitSphereRadius(0.5f);
	RootComponent = CollisionComponent;

	Mesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("Mesh"));
	Mesh->SetRelativeRotation(FRotator(0, 0, 0), false);
	Mesh->AttachTo(RootComponent);

	AudioComponent = ObjectInitializer.CreateDefaultSubobject<UAudioComponent>(this, TEXT("AudioComponent"));
	AudioComponent->bAutoActivate = false;
	AudioComponent->bAutoDestroy = false;
	AudioComponent->AttachParent = RootComponent;

	ExplosionPCS = ObjectInitializer.CreateDefaultSubobject<UParticleSystemComponent>(this, TEXT("ExplosionPCS"));
	ExplosionPCS->bAutoActivate = false;
	ExplosionPCS->bAutoDestroy = false;
	ExplosionPCS->AttachParent = RootComponent;

	ProjectileMovement = ObjectInitializer.CreateDefaultSubobject<UProjectileMovementComponent>(this, TEXT("ProjectileComponent"));
	ProjectileMovement->UpdatedComponent = CollisionComponent;
	//ProjectileMovement->OnProjectileStop.AddDynamic(this, &AsbrProjectile::OnImpact);
	ProjectileMovement->OnProjectileStop.AddDynamic(this, &AsbrProjectile::OnImpact);
	ProjectileMovement->InitialSpeed = 3000.f;
	ProjectileMovement->MaxSpeed = 3000.f;
	ProjectileMovement->bRotationFollowsVelocity = true;
	ProjectileMovement->bShouldBounce = true;
	ProjectileMovement->Bounciness = 0.3f;
}
void UTangoARCamera::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
	if (UTangoDevice::Get().GetCurrentConfig().AreaDescription.UUID.Len() > 0)
	{
		FrameOfReference = FTangoCoordinateFramePair(ETangoCoordinateFrameType::AREA_DESCRIPTION, ETangoCoordinateFrameType::CAMERA_COLOR);
	}
	else
	{
		FrameOfReference = FTangoCoordinateFramePair(ETangoCoordinateFrameType::START_OF_SERVICE, ETangoCoordinateFrameType::CAMERA_COLOR);
	}

	if (ARScreen == nullptr && TangoARHelpers::DataIsReady())
	{
		ARScreen = NewObject<UTangoARScreenComponent>(this, TEXT("TangoCameraARScreen"));
		if (ARScreen)
		{
			ARScreen->RegisterComponent();
            ARScreen->AttachToComponent(this, FAttachmentTransformRules::KeepWorldTransform, NAME_None);

			FVector2D LowerLeft, UpperRight, NearFar;
			TangoARHelpers::GetNearPlane(LowerLeft, UpperRight, NearFar);
			FVector2D UVShift = TangoARHelpers::GetARUVShift();

			NearFar.Y *= 0.99f;
			FVector LL = FVector(NearFar.Y, LowerLeft.X*(NearFar.Y / NearFar.X), LowerLeft.Y*(NearFar.Y / NearFar.X));
			FVector UR = FVector(NearFar.Y, UpperRight.X*(NearFar.Y / NearFar.X), UpperRight.Y*(NearFar.Y / NearFar.X));

			ARScreen->SetRelativeLocation((LL + UR)*0.5f);
			ARScreen->SetRelativeRotation(FQuat::Identity);
			ARScreen->SetRelativeScale3D(FVector(1, FMath::Abs(UR.Y - LL.Y) / (100.0f*(1.0f - 2.0f*UVShift.X)), FMath::Abs(LL.Z - UR.Z) / (100.0f*(1.0f - 2.0f*UVShift.Y))));
		}
		else
		{
			UE_LOG(ProjectTangoPlugin, Error, TEXT("UTangoARCamera::TickComponent: Could not instantiate TangoARScreen for TangoARCamera. There will be no camera passthrough."));
		}
	}
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	if (UTangoDevice::Get().getTangoDeviceMotionPointer())
	{
		FTangoPoseData LatestPose = UTangoDevice::Get().getTangoDeviceMotionPointer()->GetPoseAtTime(FrameOfReference, 0);
		//Only move the component if the pose status is valid.
		if (LatestPose.StatusCode == ETangoPoseStatus::VALID)
		{
			SetRelativeLocation(LatestPose.Position);
			SetRelativeRotation(FRotator(LatestPose.QuatRotation));
		}
	}
	else
	{
		UE_LOG(ProjectTangoPlugin, Warning, TEXT("UTangoARCamera::TickComponent: Could not update transfrom because Tango Service is not connect or has motion tracking disabled!"));
	}

	if (!ViewExtension.IsValid() && GEngine)
	{
		TSharedPtr< FTangoViewExtension, ESPMode::ThreadSafe > NewViewExtension(new FTangoViewExtension(Cast<ITangoARInterface>(this)));
		ViewExtension = NewViewExtension;
		GEngine->ViewExtensions.Add(ViewExtension);
	}
}
void AMMO_Character::ShootArrow()
{
	if(Role<ROLE_Authority)
	ArrowsLeft--;

	FActorSpawnParameters spawnParams;
	spawnParams.Owner = this;
	spawnParams.Instigator = Instigator;

	FVector SpawnLoc = FVector(0);
	FVector DirHelper = FVector(0);
	if (LockedTarget)
	{
		SpawnLoc = Player_SkeletalMeshComponent->GetComponentLocation();
		DirHelper = LockedTarget->GetActorLocation() - SpawnLoc;
	}
	else
	{
		SpawnLoc = ShootingLocation->GetComponentLocation();
		DirHelper = LastKnownLocationOfTarget - SpawnLoc;
	}
	
	FRotator SpawnRot = Player_SpringArmComponent->GetComponentRotation() + FRotator(0,-90,0);

	if(Role == ROLE_Authority)
	FinalArrowDamage = BaseAttack + FMath::RandRange(AttackBonusMin, AttackBonusMax);

	AArcherArrow* OurNewObject = GetWorld()->SpawnActor<AArcherArrow>(MyArrowObject, SpawnLoc , SpawnRot, spawnParams);
	

	OurNewObject->ApplyForce(ArrowForce, this, DirHelper.GetSafeNormal());
}
ATrainingDayCharacter::ATrainingDayCharacter()
{
	// Set size for collision capsule
	GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);

	// set our turn rates for input
	BaseTurnRate = 45.f;
	BaseLookUpRate = 45.f;

	// Don't rotate when the controller rotates. Let that just affect the camera.
	bUseControllerRotationPitch = false;
	bUseControllerRotationYaw = false;
	bUseControllerRotationRoll = false;

	// Configure character movement
	GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...	
	GetCharacterMovement()->RotationRate = FRotator(0.0f, 540.0f, 0.0f); // ...at this rotation rate
	GetCharacterMovement()->JumpZVelocity = 600.f;
	GetCharacterMovement()->AirControl = 0.2f;

	// Create a camera boom (pulls in towards the player if there is a collision)
	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
	CameraBoom->AttachTo(RootComponent);
	CameraBoom->TargetArmLength = 300.0f; // The camera follows at this distance behind the character	
	CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller

	// Create a follow camera
	FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
	FollowCamera->AttachTo(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
	FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm

	// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character) 
	// are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++)
}
示例#30
0
AMutagenPlayer::AMutagenPlayer(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	// Set size for collision capsule
	GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);

	// set our turn rates for input
	BaseTurnRate = 45.f;
	BaseLookUpRate = 45.f;

	// Don't rotate when the controller rotates. Let that just affect the camera.
	bUseControllerRotationPitch = false;
	bUseControllerRotationYaw = false;
	bUseControllerRotationRoll = false;

	// Configure character movement
	GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...	
	GetCharacterMovement()->RotationRate = FRotator(0.0f, 540.0f, 0.0f); // ...at this rotation rate
	GetCharacterMovement()->JumpZVelocity = 600.f;
	GetCharacterMovement()->AirControl = 0.2f;

	// Create a camera boom (pulls in towards the player if there is a collision)
	cameraBoom = ObjectInitializer.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("CameraBoom"));
	cameraBoom->AttachTo(RootComponent);
	cameraBoom->TargetArmLength = 300.0f; // The camera follows at this distance behind the character	
	cameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller

	// Create a follow camera
	followCamera = ObjectInitializer.CreateDefaultSubobject<UCameraComponent>(this, TEXT("FollowCamera"));
	followCamera->AttachTo(cameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
	followCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
}