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

2013/9/8

how to make it move forward?

mateenozil mateenozil

2013/9/8

#
Hello, I recently tried the tutorial 6 about the rocket thingy. I tried to make it move with this code on the rocket class " if(Greenfoot.isKeyDown("up")){ move(1); } " All i get is the rocket move sideways instead of forward. How do i get it to move forward?
Gevater_Tod4711 Gevater_Tod4711

2013/9/8

#
If you add this code to the constructor of your rocket class it should work:
public Rocket() {
    getImage().rotate(90);//if your rocket now moves backwards try using 270 instead of 90;
}
SPower SPower

2013/9/8

#
Well, I think you need to know more about what's going on. First, the move methods does move the object in question forward, based on the rotation of the object. When the rotation is 0, the object is pointed to the right, and bigger rotations rotate the object clockwise. So 90 degrees points down, 180 right, 270 up, and 360 right again (a full rotation, so is the equivalent of 0).
danpost danpost

2013/9/8

#
SPower wrote...
..., 180 right, ...
I am sure that SPower meant '..., 180 left, ...' (brain going faster than fingers -- I hope so). Also, to qualify, when an Actor object is created, it is always at a rotation of zero degrees; and if the image you give it is not oriented so that movement to the right is not visually forward for the actor, you need to either re-save the image with the proper orientation or use the 'rotate' method on the image to use the 'move' method on the actor. As an alternative, you could use a 'turn-move-turn' combination to accomplish this.
// example if initial rocket image points up
turn(-90); // turn actor to face upward
move(speed);
turn(90); // reset rotation of actor
SPower SPower

2013/9/8

#
@danpost Exactly, sorry! (and that's a good way of saying what's happening, it happens to me ALOT, so that's helpful!)
mateenozil mateenozil

2013/9/8

#
thanks for the reply mate :) I appreciate it.
You need to login to post a reply.