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"

[Noob question] Moving a pawn relative to the world space

Hi, I'm really struggling to get this to work. Would really appreciate a nudge in the right direction.

I have an actor, which can move up/down and left/right. When this actor is rotated 90deg clockwise, up is becoming left.

I can't get it to stay moving forward, based on it's current rotation (amazing diagram below).

alt text

My current implimentation is as follows:

 void AZumoPlayer::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
     PlayerPawnInput.Sanitize();
 
     //Move the Player
     FVector DesiredMovementDirection = FVector(PlayerPawnInput.MovementInput.Y, PlayerPawnInput.MovementInput.X, 0.0f);    
     FVector CurrentPos = GetActorLocation();
     CurrentPos.X += DesiredMovementDirection.X * MoveSpeed * DeltaTime;
     CurrentPos.Y += DesiredMovementDirection.Y * MoveSpeed * DeltaTime;
     SetActorLocation(CurrentPos);
 }

Any help is appreciated. I'm new to ue4 c++ and really having a lot of trouble working this one out.

Product Version: UE 4.18
Tags:
untitled.jpg (6.4 kB)
more ▼

asked Nov 09 '17 at 07:10 AM in C++ Programming

avatar image

DJRD4465
13 2 4 8

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

i would rotate "DesiredMovementDirection "

 FVector DesiredMovementDirection = FVector(PlayerPawnInput.MovementInput.Y, PlayerPawnInput.MovementInput.X, 0.0f);    
 DesiredMovementDirection =GetActorRotation().RotateVector(DesiredMovementDirection)

that should work ( you might have to swap your X and Y though )

more ▼

answered Nov 09 '17 at 12:31 PM

avatar image

Firefly74
1.3k 13 17 31

avatar image DJRD4465 Nov 11 '17 at 10:27 AM

Dude, I forgot to reply when I implemented this, but this works flawlessly. Thank you so much.

I would've thought you could add movement in relation to the pawn using AddActorLocalLocation() [or something along those lines] but this didn't seem to work when I tried it.

(comments are locked)
10|2000 characters needed characters left
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