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

2016/1/19

Getting the turn value

Agent546 Agent546

2016/1/19

#
So i have this gun that turns to follow the mouse, i do this by using the turnTowards tool. Im trying to figure out now how to make it fire a bullet in that direction. If i use turnTowards on the bullet it will always follow, unless i create a counter so that it only does it once but there must be an easier way to do that.
Super_Hippo Super_Hippo

2016/1/19

#
Use the 'turnTowards' on the bullet when creating it, not in the act method.
danpost danpost

2016/1/19

#
Super_Hippo wrote...
Use the 'turnTowards' on the bullet when creating it, not in the act method.
For example:
// instead of this
getWorld().addObject(new Bullet(), getX(), getY());
// create the bullet before adding it into the world like this
Actor bullet = new Bullet();
// then you can follow that with
getWorld().addObject(bullet, getX(), getY());
bullet.setRotation(getRotation());
Of course, this is after you use 'turnTowards' to have the gun face the mouse pointer.
You need to login to post a reply.