Landing on a certain side

Discussion in 'Programming' started by Jeff, May 15, 2019.

  1. Jeff

    Jeff Member

    Oct 4, 2017
    I was creating a simple game where a square will jump and rotate. The object would not always land on a side and it would sometime land on a corner. I was wondering if there was a way so that the square always lands on one of its sides and not on a corner?
  2. obscene

    obscene Member

    Jun 21, 2016
    You probably want to just "snap" it to a side when it lands, setting it's angle to whichever is closer of 0, 90, 180 or 270 ( or if it looks the same either way, just 0 ).

    You can do this by...
    1 Divide the angle by 90. This will give you a value between 0 and 3.
    2 Floor it so you get exactly 0,1,2 or 3.
    3 Multiply it by 90 again.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice