NokiMo
Megan Fox
Megan Fox

patreon


Mirroring for skateboard tricks

So let's say you want to implement a Crooked Grind in your game, for some reason. It looks like this.

The front truck is grinding along the rail, while the back end of the board is pointed out away from the rail a bit. The important bit is that the board isn't at a clean angle - it's rotated about 20 degrees out, 30 degrees up, and even has a bit of twist.

Now comes the fun part.

So you start skating, with whatever dominant foot forward, and you do a crooked grind. It looks like that. Now you go up a ramp, roll back down, and now your other foot is forward. Now you go do a crooked grind again.

It still looks like that. You crooked grind with whatever your front truck (the wheel assembly) is at that point. Which means you need to somehow get your one crook animation to work at either end of the board. Fun!

Your initial thought might be that you need to mirror the heading of the skateboard. You're very wrong. Ok, maybe we don't mirror it lengthwise, but we mirror it end to end! You're still wrong. It isn't a mirroring problem, even if it feels like it should be.

At this point I recommend drawing the problem out. I spent something like a week total on this problem, partly because I didn't start with a drawing. Once I drew it out, the solution was much clearer.

The arrow to the left indicates the direction we're sliding. The arrow inside the board indicates the way the board is facing. Skateboards have a front end (nose) and a back end (tail), which matters more than you think - but here it helps us establish what's happening.

First! Note that you do NOT need to mirror the rotation around Y. We're looking at the board top-down here, and in both cases, the board is rotating clockwise so that the relative-nose is sliding along the rail. So mirroring is straight out, see?

Now let's consider tilt. Look at the image way at the top again. See how the front is tilted down and scraping, while the back end is popped back up? That's rotation about X on the skateboard. THAT, we have to negate.

Don't forget the board twist, the rotation about the board's Z. Still, look close. We don't need to mirror that either! If you're leaning on the board such that the long edge further from the rail is tilting down a bit, that's the same rotation for both of these. So that's sorted.

But there's one more critical element here. If you're positioning this in relative space from the rail you're grinding along, and the board is pointed backwards (the arrow is down), you ALSO have to apply a 180-degree spin about Y first thing. That gets the board to the right initial rotation, and THEN you can apply the above trick rotation with no mirroring but the negated X rot.

Phew. Oh and you also need to negative any position offset along the Z axis (along the length of the rail), but that's easy.

So anyways, that took like... a week, or so, to figure out. Largely because I got hung up on mirroring. I thought I had to mirror the whole thing, and the mirror logic I had even had a bug in it, so woof. Thank god I didn't need to mirror!

Narrator: She did, in fact, have to mirror

So we only covered two of the four permutations. Here's the thing.

What if you're on the other side of the rail when you start grinding?

Yep. Ok. SO. For this, you can in fact get away with mirroring. You do the above logic first, then if you're on the other side of the rail, mirror "whatever orientation you just calculated". You also need to negate the X offset from the rail you were using.

It bears mentioning at this point, though, that... mirroring an orientation doesn't work like you think it does.

Mirroring A Heading

First off, no, you can't just mirror the rotation. You will find equations to mirror a quaternion. Unless you're much smarter than me, don't use them, because you have no idea what that means. Quaternions don't HAVE headings. (0,0,0,1) doesn't point at a neutral forward, it just doesn't... point.

Anywhere.

For that matter, the rotation you apply to bend your forward vec over 45 degrees does not, necessarily, mirror to spin negative 45 degrees around the same axis. It isn't entirely clear WHERE that mirrors, since what a quaternion is is... messy.

So let's be dumb and do it in a straightforward way. Instead, what you're gonna do is take the Quaternion that defines your heading, and you're gonna multiply it by neutral forward (forward Z probably), and then ALSO multiply it by neutral up (Y up probably). Now you have 2 nice, normal vectors. Those are easy to mirror. Mirror them.

Now compose your new mirrored forward and up into a new quaternion, and... gosh, you just mirrored the heading! But without your brain melting! Go you!

So there you go, now you know how much work goes into one absurdly obscure part of a skate game (and more importantly learned some neat tricks and gotchas about coordinate spaces and mirroring). My gut is that Tony Hawk games didn't even do all of this. I bet they straight up animated, say, the Crooked grind - four separate times, straight up. For each permutation. I don't think they could have mirrored the skeletal animation sufficiently to pull off a single animation. Still, maybe they did, and if anyone knows, I'd LOVE to hear about it.

$3+ people, look at the next post for your source code! You get to see how the sausage is made. (it is not pretty)


Related Creators