Hello,
i tried to make some sort of projectile that get directly aimed at the player when launched. But it should not follow the player constantly.
I put this code in the constructor of the projectile class(because it should only be called once):
But somehow i get this error:
1 2 3 4 5 | public void aim() { Spaceship spaceship = (Spaceship)getWorld().getObjects(Spaceship. class ); turnTowards(spaceship.getX(), spaceship.getY()); } |
java.lang.NullPointerException
at Projectile.aim(Projectile.java:26)
at Projectile.<init>(Projectile.java:17)
What exactly is causing this, because the spaceship is in the world, aswell as the projectile and how do i fix this?
Thanks :)