예제 #1
0
void ATP_TwinStickPawn::Tick(float DeltaSeconds)
{
	// Find movement direction
	const float ForwardValue = GetInputAxisValue(MoveForwardBinding);
	const float RightValue = GetInputAxisValue(MoveRightBinding);

	// Clamp max size so that (X=1, Y=1) doesn't cause faster movement in diagonal directions
	const FVector MoveDirection = FVector(ForwardValue, RightValue, 0.f).GetClampedToMaxSize(1.0f);

	// Calculate  movement
	const FVector Movement = MoveDirection * MoveSpeed * DeltaSeconds;

	// If non-zero size, move this actor
	if (Movement.SizeSquared() > 0.0f)
	{
		const FRotator NewRotation = Movement.Rotation();
		FHitResult Hit(1.f);
		RootComponent->MoveComponent(Movement, NewRotation, true, &Hit);
		
		if (Hit.IsValidBlockingHit())
		{
			const FVector Normal2D = Hit.Normal.GetSafeNormal2D();
			const FVector Deflection = FVector::VectorPlaneProject(Movement, Normal2D) * (1.f - Hit.Time);
			RootComponent->MoveComponent(Deflection, NewRotation, true);
		}
	}
	
	// Create fire direction vector
	const float FireForwardValue = GetInputAxisValue(FireForwardBinding);
	const float FireRightValue = GetInputAxisValue(FireRightBinding);
	const FVector FireDirection = FVector(FireForwardValue, FireRightValue, 0.f);

	// Try and fire a shot
	FireShot(FireDirection);
}
예제 #2
0
void AShipPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	if (bUseFuel)
		FuelReserve += FuelRecoveryRate;

	const FVector MoveDirection = FVector(GetInputAxisValue(MoveForwardBinding), GetInputAxisValue(MoveRightBinding), 0.f).GetClampedToMaxSize(1.0f);
	const float MoveDirectionSizeSquared = MoveDirection.SizeSquared();
	if (MoveDirectionSizeSquared > 0.2f)
	{
		MeshComponent->SetRelativeRotation(MoveDirection.Rotation());

		auto base_force = 1000 * MeshComponent->GetForwardVector() * MovementSpeed;
		auto input_thrust = 0.0f;
		if (bUseSeparateThrusterAxes)
		{
			input_thrust = GetInputAxisValue(ForwardThrustBinding);
		}
		else
		{
			input_thrust = MoveDirectionSizeSquared;
		}

		if (bUseFuel)
		{
			FuelReserve -= input_thrust * FuelUsageRate;
			if (FuelReserve < 0)
				FuelReserve = 0.0f;
		}

		if (bUseShipMomentum)
		{
			MeshComponent->AddForce(base_force * DeltaTime * MeshComponent->GetMass());
		}
		else
		{
			MeshComponent->SetPhysicsLinearVelocity(base_force / 50);
		}
	}
}
예제 #3
0
void AKappaPawn::Tick(float DeltaSeconds)
{
    GEngine->AddOnScreenDebugMessage(0, 5.f, FColor::Yellow, FString::FromInt(Score));

    // Find movement direction
    const float ForwardValue = GetInputAxisValue(MoveForwardBinding);
    const float RightValue = GetInputAxisValue(MoveRightBinding);

    // Clamp max size so that (X=1, Y=1) doesn't cause faster movement in diagonal directions
    const FVector MoveDirection = FVector(ForwardValue, RightValue, 0.f).GetClampedToMaxSize(1.0f);

    // Calculate  movement
    const FVector Movement = MoveDirection * MoveSpeed * DeltaSeconds;

    // If non-zero size, move this actor
    if (Movement.SizeSquared() > 0.0f)
    {
        const FRotator NewRotation = Movement.Rotation();
        FHitResult Hit(1.f);
        RootComponent->MoveComponent(Movement, NewRotation, true, &Hit);

        if (Hit.IsValidBlockingHit())
        {
            const FVector Normal2D = Hit.Normal.GetSafeNormal2D();
            const FVector Deflection = FVector::VectorPlaneProject(Movement, Normal2D) * (1.f - Hit.Time);
            RootComponent->MoveComponent(Deflection, NewRotation, true);
        }
    }

    // Create fire direction vector
    /*const float FireForwardValue = GetInputAxisValue(FireForwardBinding);
    const float FireRightValue = GetInputAxisValue(FireRightBinding);
    const FVector FireDirection = FVector(FireForwardValue, FireRightValue, 0.f);*/
    FVector WorldPosition, WorldDirection;
    APlayerController* MyController = Cast<APlayerController>(GetController());
    MyController->DeprojectMousePositionToWorld(WorldPosition, WorldDirection);

    const FVector FireDirection = FVector(WorldDirection.Component(0), WorldDirection.Component(1), 0.f);
    // Try and fire a shot
    FireShot(FireDirection);
}