Sunday, May 28, 2017

unity - How to achieve 2D ski movements similar to Alto Adventure?


I'm trying to achieve 2d movement similar to Alto's Adventure with Unity 2D. When grounded I want the character to slide alone the terrain parallel to the slope, but I want to be able to freely rotate the character in mid air. In my current failed implementation I tried using a 2d collider attached to an gameobject with a movement custom script. I'm using vertical and horizotal raycast to detect the slopes, and the object rotates based on the angle of the slope. Long story short I've given up on this implementation for now.



Do you guys have any suggestions or pointers on achieving this type of movement?



Answer



In Alto's Adventure, the terrain is dynamically generated over time, by concatenating prefabricated patterns (for example the super steep slope where you can perform a triple backflip, or any other soft slopes) in a randomic way to keep the game various from play to play.


A possible implementation can be treating these "pieces" of terrain as vertices, from which it is possible to compute normal vectors and set the facing direction of your snowboarder accordingly.


About distinguishing between sliding and jumping, you can perform some checking during each game step:



  • If the user pressed/tapped for jump, perform the jump action. This applies if there's a collision underneath the player and only when key is pressed, not while it's being pressed;

  • If there's a collision under the player model:

    • Change speed and direction of the player according to the direction of normal vector of the terrain - to draw the player standing upright;




  • Else, if the player is mid-air:

    • If input key is being pressed, increase the drawing angle; if not, do nothing or change it to reach the right value to draw the player upstanding.




While the terrain is generated dynamically by jointing pre-made pieces of terraing, interacting objects - such as rocks, fireplaces, roofs, coins - are placed randomly so that they don't intersect each other (exception for coins, they can be both below or above a grind wire, for example).


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...