This site requires JavaScript, please enable it in your browser!
Greenfoot back
ebollinger@sonorahigh.net
ebollinger@sonorahigh.net wrote ...

2018/11/29

VERY URGENT

I cant find a way to know how to shoot a bullet in the direction of my mouse click.
danpost danpost

2018/11/29

#
ebollinger@sonorahigh.net wrote...
I cant find a way to know how to shoot a bullet in the direction of my mouse click.
It is quite straight-forward:
if (Greenfoot.mouseClicked(null))
{
    Bullet bullet = new Bullet()
    getWorld().addObject(bullet, getX(), getY());
    MouseInfo mouse = Greenfoot.getMouseInfo();
    bullet.turnTowards(mouse.getX(), mouse.getY());
}
You need to login to post a reply.