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

2015/8/23

How to make an object translate in a circle without rotating itself

karthikmasalchi karthikmasalchi

2015/8/23

#
I am trying to replicate the game One more line using greenfoot for my project.But Iam stuck at a point.Iam not able to make the objects move in a circle without them being rotated themselves.Also i need them to move in circles with respect to their centers when a key is pressed down.Please help me.........
Super_Hippo Super_Hippo

2015/8/23

#
Show what you have tried.
fejfo fejfo

2015/8/23

#
I've seen a similar question before the trick is to get the old rotation before you spin and then reset the rotation afterwards like this :
//call spin from your act method
int centreX;
int centreY;
int currantRotation = 0;
public void spin(int radius,int rotationSpeed) {
    int oldRotation = getRotation();
    currantRotation+=rotationSpeed;
    setRotation(currantRotation);
    setLocation(centreX,centreY);
    move(radius);
    setRotation(oldRotation);
}
You need to login to post a reply.