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 strafe without affecting forward velocity?

I'm working on an infinite runner type game where the player character has a constantly increasing forward velocity.

I allow the player character to strafe side to side to avoid obstacles. However, this seems to reduce the player's forward velocity to about 70% of it's maximum. I do not want this to occur, as it makes my game 30% easier.

Is there any way I can allow the player character to move side to side without affecting its forward velocity? I've played around with adding forces and impulses but it doesn't seem to work very well.

I found a related thread on the UDK forum: https://forums.epicgames.com/threads/928004-Vehicle-strafe-slows-down-forward-speed, but I'm not sure how to implement this.

Product Version: Not Selected
more ▼

asked Apr 19 '15 at 01:23 PM in Blueprint Scripting

avatar image

100 13 14 22

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

2 answers: sort voted first

What's happening is the strafe velocity + forwardspeed is coming up against the maxwalkspeed value, so it clamps forward velocity when strafing to avoid exceeding your maxwalkspeed (so that character overall speed stays consistent).

You either need to figure out how to restrict forward speed to some value below maxwalkspeed (perhaps using the 'launch character' node with velocity override setting to drive your forward motion?), or you need to dynamically adjust the maxwalkspeed depending on the expected movement vector when you are strafing.

I would first try the launch character w/ velocity override method to see if it can be used to set your forward motion velocity every frame...the expected vector calculation and dynamic adjustment of maxwalkspeed would be a tad more complicated.

But if you want a starting point for how to do the vector calculation it would be something like this:

It would need to be done on a frame by frame basis, so you can add some nodes after your "add movement input" function for your strafe movement, since this executes every frame.

So you need to calculate the expected future velocity vector when you press a strafe key while walking forward to know the speed needed.

Calculate your forward vector: you can use "get forward vector" and multiply by the current forward speed. If your forward speed is dynamic you may need to use "get velocity" and "break vector" to pull the most recent forward speed...assuming forward is only ever along one axis.

Calculate your strafe vector: You would use the Inputaxis MoveRight axis value (it is 0 if not pressed, -1 for left strafe, 1 for right strafe) multiplied by the "get right vector". So use a [float * vector] node to calculate this. This gives the direction, but what about the magnitude?

For the magnitude of this vector in a given frame I believe the add movement input function uses the acceleration value…I believe by default it is 2048/s^2. We just want the acceleration in a given frame. You can get the time for a given frame from the "Event tick" function(delta seconds) …so I think you take [delta seconds]* [2048, or the acceleration value]. Multiply the resulting float against your strafe vector to get your expected strafe velocity vector.

Now, take the strafe velocity vector and add it to the forward velocity vector (vector + vector) to get your expected final vector. Finally, get the 'speed' of this vector use the vector length which will give you a float, and set your new maxwalkspeed to this value.

Now, a possible issue with doing this is if your forward movement is constantly trying to accelerate to fill the new maxwalk speed void, then it may increase in velocity instead remaining constant and allowing strafe velocity to increase...I guess it depends on how things are coded underneath.

more ▼

answered Apr 24 '15 at 09:10 PM

avatar image

1 1

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

When I try this I just get a faster version of the same problem :/

I've scoured the net and can't find a simply explained solution for this problem. Would really appreciate it if someone could show in Blueprints how to make this work.


more ▼

answered Jan 12 '19 at 05:06 PM

avatar image

46 1 3 6

(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