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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How to look around with the mouse?

I'm getting nowhere with this, I've been trying for days now but still nothing, how hard could it be to achieve something this simple?!

Anyway, here goes. I created a new blank Code project with no starter content. I then created a Pawn class and then added a mesh component and a camera component to it. That's all really, simple. The mesh is the inside of the "cockpit"/cabin and the player is supposed to only be able too look around with the mouse, no other player input. The player should be moving along a predefined path, and I got that working, but I can't look around. So I tried setting the camera to use the pawn's control rotation, and then it worked! Now I can look around! Yeay! But... when the "cart" (or vehicle) start turning, the camera does not follow, it keeps looking in the same direction, making it look like the player is turning his head in the opposite direction then the cart is turning. And I have tried with all the settings I can find, for inheriting rotation from the parent and all that, but nothing works. So I tried getting the axis values from the axis mapping, but that only make the game crash.

Let's look at some code:

 :: HEADER ::
 #pragma once
 #include "GameFramework/Pawn.h"
 #include "EgoCarPawn.generated.h"
 class BLANKPROJECT_API AEgoCarPawn : public APawn
     class USceneComponent* CarPivot;
     class UStaticMeshComponent* CarMeshComponent;
     class UCameraComponent* DriverCamera;
     virtual void BeginPlay() override;
     virtual void Tick( float DeltaSeconds ) override;
     virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
 :: SOURCE ::
 #include "BlankProject.h"
 #include "EgoCarPawn.h"
     PrimaryActorTick.bCanEverTick = true;
         // Creates the base pivot for the car, this is what gets position and rotation updated in the Tick-function
     CarPivot = CreateDefaultSubobject<USceneComponent>(TEXT("CarPivot"));
     RootComponent = CarPivot;
         // attach a mesh and adjust its postion and rotation to look correct
     CarMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticComponent"));
     static ConstructorHelpers::FObjectFinder<UStaticMesh>CarMesh(TEXT("StaticMesh'/Game/Models/car.car'"));
     CarMeshComponent->SetRelativeRotation(FRotator(0.f, 180.f, 90.f));
     CarMeshComponent->SetRelativeLocation(FVector(450.f, 0.f, 0.f));
         // Attach and setup the camera    
     DriverCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("Driver Camera"));
     DriverCamera->bUsePawnControlRotation = false;
     DriverCamera->SetRelativeLocation(FVector(310.f, -145.f, 39.f));
     DriverCamera->SetRelativeRotation(FRotator(180.f, 0.f, -90.f));
     DriverCamera->FieldOfView = 90.f;
 void AEgoCarPawn::BeginPlay()
 void AEgoCarPawn::Tick( float DeltaTime )
     Super::Tick( DeltaTime );
         // ****
         // code for getting the cars position and rotation goes here ..... cant show you
         // ****
         // Use the values that came from the hidden code above, to update the position and rotation of the car in the world, all this works fine
     CarPivot->SetWorldLocation(FVector(x, y, z));
     CarPivot->SetRelativeRotation(FRotator(pitch, yaw, roll));
         // This is suppose to make the camera rotate when the player moves the mouse, but instead it crashes the game
     FRotator HeadRotation = DriverCamera->RelativeRotation;
     HeadRotation.Pitch += InputComponent->GetAxisValue(TEXT("LookUp"));
     HeadRotation.Yaw += InputComponent->GetAxisValue(TEXT("LookRight"));
     DriverCamera->RelativeRotation = HeadRotation;
 void AEgoCarPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)

Why is the game crashing and how do I get the axis value from the mapped axis so I can modify the cameras rotation? It sounds like such a simple and basic thing to do in a game engine, but I can wrap my head around how Unreal works here.

Thanks for your time!

Product Version: UE 4.8
more ▼

asked Jul 07 '15 at 03:09 PM in C++ Programming

avatar image

Kristoffer Helander
22 9 11 15

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

1 answer: sort voted first

I was able to figure it out. I changed the rotation code at the bottom of the Tick-function to this instead, and it works.

more ▼

answered Jul 10 '15 at 06:26 AM

avatar image

Kristoffer Helander
22 9 11 15

avatar image Kristoffer Helander Jul 10 '15 at 06:28 AM

But I can't really see what's different between what that code does and what this one did:

 FRotator HeadRotation = DriverCamera->RelativeRotation;
 HeadRotation.Pitch += InputComponent->GetAxisValue(TEXT("LookUp"));
 HeadRotation.Yaw += InputComponent->GetAxisValue(TEXT("LookRight"));
 DriverCamera->RelativeRotation = HeadRotation;

Both code snippets are manipulating the RelativeRotation. But the new code is calling a function and the old one is assigning a variable, I guess that's the difference? But the old code was taken from the Vehicle example project, it's the code that works with the Oculus or other head mounted display. How come it doesn't work with the mouse?

(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