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"

Setting player rotation using gampad input axis

I am trying to recreate behavior found in the "Twin Stick Shooter" tutorial series in C++, but have hit a wall when it comes to rotation.

For reference here is the blueprint I am trying to recreate in C++: alt text

The following is the code I have currently. It gets the LookUpAxis and LookRightAxis value from a SetLookUpAxis() and SetLookLeftAxis() function that is called through the InputComponent->BindAxis lines (Not shown in the image but included in the 'SetupPlayerInputComponent' function). No error lines are shown but this does produce the error "left of '.X' must have a class/struct/union". I have tried treating it like a traditional function by typing it as .X() but that does not work.

alt text

Any help or ideas as to how I could do this better would be greatly appreciated. Thanks.

Product Version: UE 4.10
Tags:
code.png (44.0 kB)
more ▼

asked Feb 15 '16 at 10:13 PM in C++ Programming

avatar image

Decdot
26 1 3 8

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

2 answers: sort voted first

FVector::Rotation is a function, so that line should just be

 const FRotator RotationValue = AxisVector.Rotation();

and that gives you the FRotator you want to pass in to SetRelativeLocation (this is assuming AMyPaperCharacter is never rotated, I would probably use SetComponentRotation instead). The function should look something like

 FVector AxisVector = FVector(LookUpAxis, LookLeftAxis, 0.0f);
 const float AxisVectorSize = AxisVector.Size();
 
 if(AxisVectorSize > 0.25f)
 {
     Weapon->SetComponentRotation(AxisVector.Rotation());
 }
more ▼

answered Feb 15 '16 at 11:16 PM

avatar image

kgamble
924 42 61 209

avatar image Decdot Feb 16 '16 at 12:03 AM

Thanks for your suggestion but unfortunately it was not the solution. I am only looking to rotate the "Weapon" object by the Pitch value, so the player essentially points in the direction they wish to fire. Using AxisVector.Rotation() in the SetRelativeRotation() function did something quite different. Also the "SetComponentRotation" function you suggested is not part of the UPaperFlipbookComponent class, which is why I decided to useSetRelativeRotation instead.

Right now I have the player class setup to have two UPaperFlipbookComponents, one (inherited from APaperCharacter) for the player sprite and one that I added to show the weapon. The second flipbook is the only one I want to rotate around its origin with player input.

avatar image kgamble Feb 16 '16 at 12:23 AM

Oh, it's SetWorldRotation that I was thinking of, it seems there's some inconsistency with the naming since the getter is called GetComponentRotation.

Anyway, looking at the code for the GetRotationXVector node in that blueprint it's just a call to vector.Rotation() so I'm not sure why it's not working for you. I haven't used Paper2D that much so hopefully someone else can help.

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

I managed to get the results I was looking for by only using the .Yaw value of Rotation() and applying it to the weapons pitch by using "Weapon->SetWorldRotation(FRotator(AxisVector.Rotation().Yaw, 0.0f, 0.0f));"

more ▼

answered Feb 16 '16 at 11:37 AM

avatar image

Decdot
26 1 3 8

(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