This site requires JavaScript, please enable it in your browser!
Greenfoot back
armoredarmada
armoredarmada wrote ...

2012/4/12

Angles

armoredarmada armoredarmada

2012/4/12

#
For my helicopter game I want the helicopter to move at a certain range of angles, how would I make the code so It moves when between 90 and 120 degrees?
danpost danpost

2012/4/13

#
Since a helicopter moves forward when the front of the helicopter is lower than the back, I will take it that your 90 degrees is horizontally level, and 120 degrees is (from 0 degrees, straight up) 30 degrees down from horizontal in the front. If the helicopter is facing to the right, then the range would be (in Greenfoot terms) 0 degrees to 30 degrees, and if facing left, 150 degrees to 180 degrees. Therefore, in pseudo-code (not exactly real code)
if (facingRight)
{ // facing right
    if (rotation >= 0 && rotation <= 30) move();
}
else
{ // not facing right
    if (rotation >= 150 && rotation <= 180) move();
}
You need to login to post a reply.