// Sets default values
ABall::ABall() :ZPos(0.f)
{
 	// 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;

	
	FRotator Rotator;
	Rotator.Add(0.f, FMath::Rand() % 360,0.f);
	SetActorRotation(Rotator);

	MovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(
		TEXT("MovementComponent"));
	MovementComponent->ProjectileGravityScale = 0.0f;
	MovementComponent->bShouldBounce = true;
	MovementComponent->Bounciness = 1.0f;
	MovementComponent->Friction = 0.0f;
	MovementComponent->BounceVelocityStopSimulatingThreshold = 0.0f;
	MovementComponent->MaxSpeed = 1000.f;
	bStartedMoving = false;
}
Exemplo n.º 2
0
void URotableActor::Rotate(const FRotator& _rotator)
{
	FRotator rot = GetOwner()->GetActorRotation();

	rot.Add(_rotator.Pitch, _rotator.Yaw, _rotator.Roll);
	float pitch = rot.Pitch;
	if (pitch > 20)
		pitch = 20;
	else if (pitch < -20)
		pitch = -20;

	float roll = rot.Roll;
	if (roll > 20)
		roll = 20;
	else if (rot.Roll < -20)
		roll = -20;

	FRotator rot2(pitch, rot.Yaw, roll);

	this->GetOwner()->SetActorRelativeRotation(rot2);
}
void ATwinStickShooterPlayerController::LookAtMouseCursor()
{
	ATwinStickShooterCharacter* const MyPawn = (ATwinStickShooterCharacter*)GetPawn();
	if (MyPawn)
	{
		// Trace to see what is under the mouse cursor
		FHitResult Hit;
		GetHitResultUnderCursor(ECC_Visibility, false, Hit);

		//Gets player rotation
		FRotator PlayerRot = MyPawn->GetActorRotation();

		//Gets the Directional Vector Ranging from -1 to 1
		FVector PlayerDirection = PlayerRot.Vector()*-1;

		//Get The right vector for your character
		FRotator PlayerRightRot = PlayerDirection.Rotation();
		PlayerRightRot.Add(0, 90, 0);
		FVector RightVector = PlayerRightRot.Vector();

		//Gets the players current location minus the Z
		FVector PlayerLoc = MyPawn->GetActorLocation() * FVector(1, 1, 0);

		//Gets Mouse location minus the Z
		FVector MouseLoc = Hit.ImpactPoint * FVector(1, 1, 0);

		//Find the Desired angle of rotation between the Player and Mouse
		FRotator PlayerDesiredRot = (PlayerLoc - MouseLoc).Rotation();
		//float FaceToAngle = PlayerDesiredRot.Clamp().Yaw;

		//Gets a Directional Vector Ranging from -1 to 1 in screenspace for the mouse from the character
		FVector MouseDirection = PlayerDesiredRot.Vector();

		//The Aim at angle for the character
		MyPawn->AimAtAngle = ((acosf(FVector::DotProduct(PlayerDirection, MouseDirection))) * (180 / 3.1415926));
	
		//Calculate the distances from all angles
		float RDist = FVector::Dist(MouseDirection, RightVector);
		float LDist = FVector::Dist(MouseDirection, RightVector*-1);
		float FDist = FVector::Dist(MouseDirection, PlayerDirection);
		float BDist = FVector::Dist(MouseDirection, PlayerDirection * -1);

		//Set bools
		if (RDist <= LDist)
		{
			MyPawn->bLookRight = true;
		}
		else
		{
			MyPawn->bLookRight = false;
		}

		if (FDist <= BDist)
		{
			MyPawn->bLookForward = true;
		}
		else
		{
			MyPawn->bLookForward = false;
		}
		//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::Printf(TEXT("Aim Right : %d :: Aim Forward : %d ::"), bLookRight, bLookForward));
	}
}