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

2013/1/7

turnTowards problem

DaBist DaBist

2013/1/7

#
Hello. I have a problem: i have an object, that moves towards a coordinate. i use turnTowards command. But my object doesn't just move, it also rotates towards a coordinate. I want it to stay as it is. How do i do that?
erdelf erdelf

2013/1/7

#
give us the code
Duta Duta

2013/1/7

#
I assume what you mean is that you want to be able to do
turnTowards(something);
move(speed);
but not have the rotation change. One way to do this is to store what the rotation was before turnTowards, and then set it back to the original rotation after it's done. What I'm trying to say is:
int oldRotation = getRotation();
turnTowards(something);
move(speed);
setRotation(oldRotation);
Minion1 Minion1

2013/1/8

#
turnTowards() is a method that automatically sets rotation. If you don't want your object to turn maybe you could try getting the x, y location of the target object and comparing it to the location of the "hunting object." The hunting object will use code that essentially says, "if x of target is greater than x of hunter, then increase hunter x, if y of target is less than hunter y, then decrease hunter y.." etc. It worked for me.
Minion1 Minion1

2013/1/8

#
Oh, and use the setLocation() method to do the actual moving.
DaBist DaBist

2013/1/8

#
Duta wrote...
I assume what you mean is that you want to be able to do
turnTowards(something);
move(speed);
but not have the rotation change. One way to do this is to store what the rotation was before turnTowards, and then set it back to the original rotation after it's done. What I'm trying to say is:
int oldRotation = getRotation();
turnTowards(something);
move(speed);
setRotation(oldRotation);
thanks, it works now :)
You need to login to post a reply.