Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Aligning a skateboard to a predicted landing point?

Discussion in 'Physics' started by LeytonViner, Apr 17, 2023.

  1. LeytonViner


    Apr 7, 2017
    Hiya! I'm currently experimenting with a skateboarding game prototype, and one thing i noticed in the Skate games is that the player automatically aligns to the point they're gonna land on (visible right at the start of this video)

    I've got a landing prediction system going, which is neat, but how do i actually align the board in such a way that it maintains the direction it's heading in? What would I use? Currently, I'm using this snippet of code when the board leaves the ground:
    Code (CSharp):
    1. predictedLandingRotation = transform.rotation * Quaternion.FromToRotation(transform.up, predictedLandingInfo.normal); //predictedLandingRotation is a quaternion
    And, during the air, I'm using this code to tilt to it:
    Code (CSharp):
    1. transform.rotation = Quaternion.Lerp(transform.rotation, predictedLandingRotation, groundReadjustmentSpeed * Time.deltaTime);
    But this doesn't work very well. The player can't spin in the air, and it is often just outright wrong. What's the correct way to do this?
  2. Turtlehellmax


    Nov 26, 2020
    I don't know if this would work consistently or not, but I would try getting the distance of two raycasts, one at the front of the board and one at the back, and then lean the board back if the front distance is less than the back distance and vice versa. Let me know whether or not this works!