As per usual, anything said during the show is subject to change by CIG and may not always be accurate at the time of posting. Also any mistakes you see that I may have missed, please let me know so I can correct them. Enjoy the show!
Bug where in the hornet if you rotate the turrets they work fine but when you stop they snap back into position and move erratically
They have old turret code that controls the movement for yaw, pitch and roll which also controls the rotation which broke
In the back end of animations there are two processes going on on two separate threads and then those two threads are supposed to sync but that broke
Mark Abent: Hey everyone, welcome to Bugsmashers. I’m you host Mark Abent, I’m a Gameplay Programmer here at CIG Los Angeles and I take you behind the scenes of some crazy bugs and funny bugs that play our game and it’s just a lot of fun to show you guys what’s happening. So, let’s take a look.
Hey everyone, we’re here in my fancy dancy test level again and I have a little Hornet here just rotating freely and as you can see all the turrets on this guy are spazzing out. They’re just going bonkers and the funny thing is if I actually rotate the turrets, they’re fine. Just as soon as you stop rotating it kind of snaps back to the old position and they’re just going crazy. So what’s happening.
Well, let’s take a look at the code. Here we are in the turret code which hasn't been touched in quite awhile and what we do is for all the axis… pitch, yaw or even roll, we want to move those bones to try to aim towards the target so if we have a point here we want the turret to rotate and look at it and if it’s down here we want to rotate it there. So, we have for each of our axis a current angle and then we have this thing called the original rotation so if this is the original rotation and we’re up here we move this way.
So we basically start here and from our current angles we move any which way we need to go. So, that’s what this bit of code here does and since we’re modifying a joint or location on a skeleton… so there’s these bones on a skeleton and that is what you use to move, like my arm there would be a joint here and I can move it up and down. Same thing on a turret, there’s going to be a joint pitch and a joint for yaw and so after we do that calculation of how much we want to move it, we now have to tell the skeleton to move to that location and this functionality right here basically says, ‘after we’re done animating, we’re going to inject this rotation’. So the turret can animate, you know deploy… it has animation to deploy down and then as it deploys, it’ll play the animation for moving up and down and then it’ll do our rotation.
This is some old code that we used for a long time and all of the sudden it decided to break because in the back end for our animations, there was a lot of steps to optimize it, buffer it so that the main thread could do something while the threaded thing could do something then there they’re supposed to sync and in between that time this process kind of broke. The unfortunate thing about this guy is after the animation has done it’s thing on a separate thread, we then modify the pose on the main thread so it’s actually a little bit taxing on the system.
Now’s there’s this new thing or this thing that’s been supported for awhile we just haven’t used it is this thing called Animation Pose and what this thing allows us to do is in the actual thread that’s where we modify the bones and we’ll actually apply the rotation. So instead of updating this old legacy thing which is now broken, we have this new thing which we can act upon, here it is, our aim pose and we can directly say, ‘all right, here’s the rotation that we want so whenever you do the animation task in the back thread we’ll assign the rotation’ and it will happen in the thread.
So even if this doesn’t happen right away because maybe it’s not visible or maybe it’s, you know, far, far away whenever it actually gets processed it will then remember the value it wanted and then go and process it. So, we’re going to use this bad boy now and as you can see here is our actual implementation where we can inject position, orientation and then whenever the thread is getting ready, we basically say, ‘all right, we’re going to switch over and then once the thread is in here we generate our task and compute the actual rotation, orientation or even both’ set by the turret or some other system.
So, let’s activate this guy and disable the old system and we do want to keep this line which will allow the rotation to happen even if it’s not visible. That’s mostly for gameplay reasons so you can’t see the guy behind you, you still want to know which way he’s shooting instead of shooting out the wrong way. So this will at least force those locations to be updated. So, let’s hit the magic recode button.
The recode is finished and before we go in, I just want to show you this little bit, because the bones can be actually in different characters because of legacy reasons. We need to make sure we only inject this pose modifier once per frame otherwise things get funky. So, now we’re back in the game and I can move my turrets all the way around and if I let go of the mouse… you’ll see they tend to stay in the location that they were last set except the top turrets and bottom turrets they’re trying to aim at the point I last specified because they’re trying to aim where I am looking on the screen and as I rotate they tend to rotate as well. If everything fires ok and they’re not twitching around like crazy then it’s good to go. Hope you guys liked.
So as you guys saw, we had a little issue where the turrets were jiggity jagging all around and it’s just because we were using an old outdated method that wasn’t working with our new streamlined double buffered command system for animations and because the two systems didn’t play well. Instead of retrofitting the old system we decided to use the actual new system which is these things called pose modifiers which when those animations happen we can say that these specific joints, you know, the arms or these turrets supposed to be some sort of action or rotation and because of that now when everything all animates our turrets nice and smooth, they’re not doing that crazy jitter. Everything looks gorgeous and just looks that much awesome and we’re using a whole new system in the thread so everything works out, getting a little bit of performance. Hope you guys enjoyed, til next time.