• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How to have an object fall naturally after being rotated in midair?

T

TGSP

Guest
So I'm making a game where a square jumps from platform to platform trying to get as high as it can without getting hit by lasers and dying. While the square is in the air he rotates. But when he lands on a platform after rotating he doesn't land flat on one of his sides. For example he may land on his corner instead. I just want to know how do I make it so that he falls naturally so after rotating he doesn't land on his corner, and he falls flush with the platform. If I wasn't very clear as to what I'm trying to ask I'll clarify if you want.
 

Hyomoto

Member
I have to admit, I don't have anything to add but your response made me laugh. That's not meant to be mean, you just need to read your response without the bias of having asked the original question.

The answer is pretty simple though. The character is a square? Well, you already know where the flush sides are: 0, 90, 180, 270. That means you just need to find the nearest 90 angle and rotate towards it.
 

GMWolf

aka fel666
AAhaaahhh, wait: Do you want it so that if he falls on his corner, he would tople over and end up flush, Or do you want it so that he will never land on a corner, because he would rotate as he falls?
 
T

TGSP

Guest
AAhaaahhh, wait: Do you want it so that if he falls on his corner, he would tople over and end up flush, Or do you want it so that he will never land on a corner, because he would rotate as he falls?
I want it so that if he falls on his corner he would topple over and end up flush with the platform
 

Hyomoto

Member
Here is a simplified version of trying to find the nearest 90 degree angle and rotating towards it:
Code:
var _rotate = direction mod 90;
    if _rotate > 45 { _rotate = _rotate - 90 }
   
    if abs( _rotate ) < 1 { direction -= _rotate } else { direction -= _rotate * 0.1 }
This has a 'smoothing' applied to it that you can get rid of by changing 0.1 to 1. However, as @Fel666 said, if you want a physics enabled version, you'll have to use physics. This just demonstrates how to rotate something to the nearest 90 angle.
 
T

TGSP

Guest
Here is a simplified version of trying to find the nearest 90 degree angle and rotating towards it:
Code:
var _rotate = direction mod 90;
    if _rotate > 45 { _rotate = _rotate - 90 }
  
    if abs( _rotate ) < 1 { direction -= _rotate } else { direction -= _rotate * 0.1 }
This has a 'smoothing' applied to it that you can get rid of by changing 0.1 to 1. However, as @Fel666 said, if you want a physics enabled version, you'll have to use physics. This just demonstrates how to rotate something to the nearest 90 angle.
Thanks for your help on this subject, I've actually decided to not use a square as the main character so I wouldn't have to worry about the issue of sitting flush with the platform after rotating mid air.
 
Top