Greetings!
I'm working on a prototype for a stealth game, and I would like some help figuring out the character movement for NPCs. While the default character movement setup is perfectly functional, it's pretty rudimentary for the level of flow I would like to see. I'm an animator, and I want the character movement to complement the animations, not work against them.
https://www.youtube.com/watch?v=W-7b0hOA55s
This is what I have at this time, currently trying out navigations through doorways. Hopefully I will soon be able to add the actual door that it can open. The only things I did after recording this is turning on "smooth" rotation. I also set up a couple of twist animation additives in a blendspace so that the creature will twist when turning. Only, it looks unappealing when the nicely interpolated animation blendspace is combined with the default linear rotation of the actual character movement.
I have been trying to affect the rotation rate so that it has more of a rubber band effect, both in and out of rotations towards a destination (which probably need different logic). Same goes for movement, but the rotation is more noticeable, so I started there.
This is more or less the kind of movement I would like to see:
https://www.youtube.com/watch?v=UOYxtmxYdJUI can post more details later, bur for now, I would appreciate any tips on general fine tuning of NPC character movement using the character blueprint template.
Replies
but to do it the normal way, i'd make turn around animations for 90 and 180 degrees
then in your blueprint, before you call for a new move-to event, check and see what the angle between current world rotation is and the next proposed location, and if its near 90 or 180 play that animation first, and bind to notify event to let you know when it is complete and start the actual move-to event then
you can probably play it as a montage, then you can easily fire event from blend out or complete of the montage.
to find the rotation difference i think you can just get current actor world rotatation and look at rotation for the next move-to location, and get the delta of the rotations
About the 90 and 180 degree turn montages, would it be possible to combine the two, in the case of odd angles like 122 degrees, or 75 degrees, or would it necessarily be limited to starting out in the directions they are animated in, as in 4 directions, or maybe 8? Maybe I'm getting ahead of myself here, it's all about hiding obvious seams and unintentionally unnatural movements to me (the monster in the scene is meant to have certain qualities in its movements that are unnerving, but technically rudimentary capsule movement in the engine does not compliment that)
About the gradual turning, having a slight arc on the character's way to a destination, I think we generally give too much slack to bipedal creatures due to having a relatively small turn radius. We generally don't give the same amount of slack to quadrupeds, or even better, cars. How often do you see cars in games linearly drifting to the right orientation and driving in a straight line to its destination?
So the character movement has a set (maximum) rotation rate. The logic has to be different between starting to orient towards the destination, and ending its orientation towards the destination, but the idea is more or less this. Feel free to correct me is this is all crackpot design, or if it's wildly overcomplicating, but some kind of natural character navigation is something I find very important:
https://www.youtube.com/watch?v=igykXKtsc9s
Now, I actually have no idea exactly how the character navigation looks under under the hood, whether the entire path is predetermined or if it doesn't receive this information until the previous in-between destination has been reached. My idea is that the in-between destinations act more like anchor points. They are not actually destinations that must be reached, but merely help the character get to where it's actually supposed to go. Each in-between destination would need to be aware of the space between it, the previous destination, and the next one, to determine how much space is available to navigate in an arc, and of course a maximum "arc" value so that the character doesn't move through a large room in one huge unnecessary arc. Likewise, if the character is very close to the destination and still hasn't managed to orient itself, THEN, it can utilize the more snappy and linear navigation just to make sure that it actually reaches its destination without missing, like a door right behind a sharp corner, or a player moving erratically.
Anyway, I'm still stuck with not being able to affect the character movement's robotic turn rate and non-existent acceleration, only animation values, which I figured out easily enough. No matter how I try to hook it up, I can't seem to figure out how to affect the value correctly. Character movement and character animation must work together to form a character that moves in a convincing way.
if high believability is what you are after, then definitely check out the new free motion matching example. Though for an indie developer it seems like an awful lot of work to deal with. But it's there and free to check out.
for effecting the character pathing, i think you'd have to dig deep into the c++ source code to understand how it works and make any direct changes. In my case, I just control how i set waypoints for character AI if I want to do something special there. Usually I create a grid of points above the actor and use some sort of rule to decide distance and direction to select one point with, and that point shoots a line trace down to find the next waypoint. Using a simple method like this its easy to do things like zig zag movement, run parallel or perpendicular to a target, etc.
given a target location and your actors current position, you know the distance to it, so you could do your own acceleration by mapping actor velocity to distance, if you wanted to.
if you have a pretty linear playspace you could probably just manually set waypoints as well. i do this for actors that are not using unreals pathfinding system, like flying actors, and it actually scales pretty easily and gives granular control.
I'm not in front of unreal at the moment but off the top of my head there are three setting that you almost always have to set before you can start working with smoother rotation.
- You want to go into your pawn, search for "Use Controller Rotation" and uncheck Y.
- Click on the "CharacterMovement" component and check on "Orient Rotation to Movement".
- This gives you access to "rotation rate" which you can tweak however you like and it will tune the speed that your character rotates.
Next you want to play with the acceleration and braking values to get them to speed up and slow down.EDIT: Matt Aspland has a decent tutorial about these settings,
How To Make AI Turn Smoothly | Smooth Rotation Turning - Unreal Engine Tutorial (youtube.com)
He doesn't appear to go into the blendspace or the values that drive it, bummer...
________________________everything below here is optional and just how I usually work___________________________________
Next you need to make the animation blending look good (idle walk, run, turns). Personally I do most of my locomotion in a 2D blendspace. So almost everything blends between each other, idle blends to walk, which blends into run. If you're using a controller and barely pushing forward you get a blend between the two. If you're using a keyboard, people tend to be very state based and binary, on or off, walk or run, no blending and I personally hate that because it makes it hard to do ease in/out or variable speeds.
A typical locomotion blendspace might look like this: (I ripped this from google image search so don't take it literally). If you struggle to set this up, post and ping me, I've set it up dozens of times and it works great. There are probably tutorials online that teach it also... hmm maybe I should make one if no one has... hmm... ha.
Vertical is Speed (-250 to 500)
- 0 is in the middle and is used for idle and "turns". The turns rotate faster as the direction increases.
- 15 degrees is a slight shuffle
- 90 is spinning in a circle.
Horizontal is Direction (-180 to 180)
- 180 is character right, -180 is character left.
- The steps in-between are the usually set to 45 degree increments because it makes the math easier.
The blendspace has interp values that you can play with that will help you dial in the speed of the blend from one animation to another.
Then it's just playing with everything until you get it to work how you want. I would start with the character movement component, get the capsule rotating how you want and then move into animations. There is a lot of work on the animation side that needs to be done after that but it really depends on if you're going to dig that deep or use off the shelf assets bla bla bla...
Figuring out Rate of Capsule Rotation
When it comes to figuring out the rate of rotation for the idle/turns, I usually keep it simple, the rate of rotation is:
"Double the degree. Over 1 sec"
- 15 degrees on the blendspace, the root in maya rotates 30 degrees over 1sec.
- 45 degrees on the blendspace, the root in maya rotates 90 degrees over 1sec.
Nice clean, works pretty well with the default rotation rate, but if you've set it to something else, you might have to do a bunch of math to figure out what the actual rotation rate is, or you can take the animator way out and print the direction and use "Take Recorder" to capture your character spinning at a set degree. You export that animation from unreal and bring that back into your DCC to help figure it out.