I am trying to get the character to fire a projectile at the coordinates of the mouse when the mouse is clicked. Currently, the projectile will fire and move at the right speed (using move() instead of a vector) but the direction stays 0.
My math for firing from the Character.class:
And the constructor for Projectile.class
if(charclass == 2)
{
MouseInfo info = Greenfoot.getMouseInfo();
double dxcalc = (info.getX()-getX());
double dycalc = (info.getY()-getY());
double dir = Math.atan2(dycalc,dxcalc);
getWorld().addObject(new Projectile(dir, true), getX(), getY());
}
public Projectile(double direction, boolean fromCharacter)
{
super(new Vector (direction, Character.Arrowspeed));
if(fromCharacter)
{
power = Character.actualdamage;
setImage(arrow);
arrow.rotate(45);
setRotation((int) direction);
arrow.scale(25,25);
}
}
