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"

Get Characters current walking speed

I have a player character derived from ACharacter and I have a function which is called every time the jump button is pressed. Now whenever that happens I want to get the velocity with which the player is moving forward (kinda its current local velocity along the X axis). So basically the walking speed at the time you jump is hoing to be stored in a float variable. I need that for wall running.

Product Version: UE 4.5
Tags:
more ▼

asked May 27 '15 at 02:41 PM in C++ Programming

avatar image

Karwler
138 10 11 26

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

2 answers: sort voted first

Got it:

 wallSpeed = FVector::DotProduct(GetVelocity(), GetActorRotation().Vector());

Thanks for the help.

more ▼

answered May 27 '15 at 06:45 PM

avatar image

Karwler
138 10 11 26

avatar image PersnicketyGareth May 27 '15 at 07:01 PM

Glad you got it solved. Make sure to 'accept' your answer so that the thread becomes listed as 'resolved'.

avatar image Jbonnett Jul 11 '16 at 06:20 AM

Is there a way to account for the side moments? I see that is method only works for forward and backward movements.

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

I would get the velocity FVector of the root component and dot product it with an X-axis: FVector(1.f,0.f,0.f).

If I remember correctly, you can also access velocity via the CharacterMovementComponent.

It would look something like this:

 FVector A = Velocity;
 FVector B = FVector(1.f,0.f,0.f);
         
 float WalkVel_X = FVector::DotProduct(A, B);
more ▼

answered May 27 '15 at 03:12 PM

avatar image

PersnicketyGareth
25 10 12 17

avatar image Karwler May 27 '15 at 04:34 PM

It doesn't seem to work. I'm getting completely "random" numbers. I'm thinking of doing something like in this: https://forums.unrealengine.com/showthread.php?7808-How-to-get-local-velocity Though I ran out of ideas how to get the forward vector of actor rotation. Also, what does the DotProduct actually do?

(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