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

2016/12/27

SetRotation

wolfyze wolfyze

2016/12/27

#
int countera=0; public void act() { int guyX = ((guy) getWorld().getObjects(guy.class).get(0)).getX(); int guyY = ((guy) getWorld().getObjects(guy.class).get(0)).getY(); double a=abs(getX()-guyX); double b=abs(getY()-guyY); double c=sqrt(pow(a,2)+pow(b,2)); double sinal=abs(a/c); int alfa=(int)(toDegrees(asin(sinal))); if(guyX<getX()&&guyY>=(getY())){ alfa=alfa+90; } if(guyX<getX()&&guyY<getY()){ alfa=alfa+180; } if(guyX>=getX()&&guyY>=getY()){ } if(guyX>=getX()&&guyY<getY()){ alfa=alfa+270; } if(countera<=1){ setRotation(alfa); } move(1); if(isTouching(guy.class)||isAtEdge()){ getWorld().removeObject(this); } countera++; } SO I was trying to make my Mushroom thing shoot green things at the player. I wanted the green balls to rotate so they fly towards him. Well now it seems that I can only use degrees that are divisible by 45... What do I do now? btw the "countera" is there so it turns only once, if i remove it the thing will follow the player around, and that works fine I think.
Super_Hippo Super_Hippo

2016/12/27

#
I think you could just use the 'turnTowards' method. The only 45-thing is probably because it only moves 1 cell each act cycle. You could import the SmoothMover class and let the green balls extend that SmoothMover class.
wolfyze wolfyze

2016/12/28

#
Wait did I actually write all this even though theres that turnTowards thing... well aren't I an idiot... I'm pretty new to greenfoot so I have no idea how to do that. :( thank you though
You need to login to post a reply.