x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

RTS camera blocking

Hello world! I am trying to create RTS game with RTS Camera Movament. I'm using this tutorial : https://youtu.be/6JAuSV4WZuc But I don't have any idea how to create Camera XY Limits (when you scroll to map border, camera don't go farther ) Please help my with this. I use c++

Product Version: Not Selected
Tags:
more ▼

asked Jan 13 '18 at 10:29 AM in C++ Programming

avatar image

betemic
1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hey there, you can define a minimum maximum X and Y for the camera to be a certain value and you can clamp it after you change the position of the camera.

more ▼

answered Jan 14 '18 at 08:40 PM

avatar image

xlar8or
6k 163 129 305

avatar image betemic Jan 14 '18 at 08:52 PM

Could you write this code. taht is what I have now ; CameraPawn.cpp

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "CameraPawn.h"
 #include "gal4.h"
 #include "GameFramework/PlayerController.h"
 
 
 
 // Sets default values
 ACameraPawn::ACameraPawn()
 {
      // 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;
 
     RootScene = CreateDefaultSubobject<USceneComponent>(TEXT("RootScene"));
     RootComponent = RootScene;
 
     SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm"));
     SpringArm->SetupAttachment(RootScene);
     SpringArm->bDoCollisionTest = false;
     SpringArm->SetRelativeRotation(FRotator(-50, 0, 0));
 
     CameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
     CameraComp->SetupAttachment(SpringArm);
 
 
 
 }
 
 // Called when the game starts or when spawned
 void ACameraPawn::BeginPlay()
 {
     Super::BeginPlay();
 
     PC = Cast<APlayerController>(GetController());
     PC->GetViewportSize(ScreenSizeX, ScreenSizeY); 
 }
 
 // Called every frame
 void ACameraPawn::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
 
     AddActorWorldOffset(GetCameraPanDirection() * CamSpeed);
 
 }
 
 FVector ACameraPawn::GetCameraPanDirection()
 {
     float MousePosX;
     float MousePosY;
     float CamDirectionX = 0;
     float CamDirectionY = 0;
 
     PC->GetMousePosition(MousePosX, MousePosY);    
     
     if (MousePosX <= Margin)
     {
         CamDirectionY = -1;
     }
 
     if (MousePosY <= Margin)
     {
         CamDirectionX = 1;
     }
 
     if (MousePosX >= ScreenSizeX - Margin)
     {
         CamDirectionY = 1;
     }
 
     if (MousePosY >= ScreenSizeY - Margin)
     {
         CamDirectionX = -1;
     }
 
     return FVector(CamDirectionX, CamDirectionY, 0); 
 }





avatar image betemic Jan 14 '18 at 08:52 PM

CameraPawn.h

// Fill out your copyright notice in the Description page of Project Settings.

 #pragma once
 
 #include "CoreMinimal.h"
 #include "GameFramework/Pawn.h"
 #include "Camera/CameraComponent.h"
 #include "GameFramework/SpringArmComponent.h"
 
 #include "CameraPawn.generated.h"
 
 UCLASS()
 class GAL4_API ACameraPawn : public APawn
 {
     GENERATED_BODY()
 
 public:
     // Sets default values for this pawn's properties
     ACameraPawn();
 
 protected:
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
 
 public:    
     // Called every frame
     virtual void Tick(float DeltaTime) override;
 
     // Called to bind functionality to input
     // Called to bind functionality to input
     virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override
     {
         Super::SetupPlayerInputComponent(PlayerInputComponent);
 
     }
 
     UPROPERTY()
     USceneComponent* RootScene;
     
     UPROPERTY()
     USpringArmComponent* SpringArm;
 
     UPROPERTY()
     UCameraComponent* CameraComp;
 
     UPROPERTY()
     APlayerController* PC;
 
     UFUNCTION()
     FVector GetCameraPanDirection();
 
     UPROPERTY()
     float Margin = 15;
 
     UPROPERTY()
     int32 ScreenSizeX; 
     
     UPROPERTY()
     int32 ScreenSizeY;
 
     UPROPERTY()
     float CamSpeed = 110; 
 };
avatar image betemic Jan 14 '18 at 08:54 PM

Write my this code for blocking camera.

avatar image xlar8or Jan 16 '18 at 01:49 AM

What do you mean?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question