0
\$\begingroup\$

Ever played Skate 3? When dropping into a ramp, or if you're midair, your player's up direction aligns to the normal of the surface you're about to land on, while respecting the player's forward direction as much as possible, while still allowing them to perform in-air 360 spins etc. How can I do this?

I've got the code for landing point prediction complete, that's not a issue. Just figuring out the rotation and actually rotating to it is proving difficult.

\$\endgroup\$
1
  • \$\begingroup\$ I'd recommend linking this question to your previous question on the same topic, to leave a breadcrumb trail for other users trying to learn from your experience. \$\endgroup\$
    – DMGregory
    Commented May 26, 2023 at 12:04

1 Answer 1

0
\$\begingroup\$

If you know the normal of the landing point, you can get the after-landing forward direction by projecting the current forward onto the plane defined by the normal.

From there, it should be possible to build a quaternion to represent the final rotation using the forward and up vectors. For example, unity has a Quaternion.LookRotation function that does this. If you have to implement this yourself, there are several examples you can find with a quick google search of how to build the quaternion from the up and forward vectors.

As for actually rotating, the easiest way is probably to interpolate over time between the current rotation and the desired after-landing rotation with a Slerp. Since you already have a prediction for the landing, you could use a fixed duration for this interpolation (say, 0.5s), and when you are 0.5s away from touching the ground, record the current rotation and start interpolating between that value and the desired rotation.

\$\endgroup\$
3
  • \$\begingroup\$ Hiya! thank you for answering this helped quite a bit. A small issue with Slerp though, I still need the player to be able to rotate around their up axis, for stuff like 180 and 360 spins and all that. I think that's probably the hard bit. \$\endgroup\$
    – AriaMath
    Commented May 26, 2023 at 10:21
  • \$\begingroup\$ Ah, I see. Well that is slightly trickier, and kind of depends on how you are handling the rotation of the spins. A possible way to handle it would be to keep two quaternions: one that indicates where "up" is for the character (this is the one that is Slerped) and another one that tells you the rotation that the character should have according to the spin animation. Then you multiply q_anim * q_up for the final rotation (I think. It might be the other way around) \$\endgroup\$
    – PepeOjeda
    Commented May 26, 2023 at 10:29
  • \$\begingroup\$ Oh okay, I'll try that! thank you so much! \$\endgroup\$
    – AriaMath
    Commented May 26, 2023 at 11:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .