Sprite direction-Asteroids: Game Lab

Working on Asteroids type game. Trying to get bullet to shoot the same direction the player is facing. Thought I had it figured it out but still not working. Could use some feedback on setting bullet direction. Here’s what I have at the moment:


Can you send us a link to your project to look at? It’s a lot easier to review / troubleshoot if we can copy/edit/play with with the code.

Also, let us know what you tried, what you expect to happen, what is happening instead, etc.

All of those things can help us to help you more efficiently.



Few notes since: seems only the animation rotates w/ rotationspeed, and not the sprite itself-stays facing same direction, which is what I’m trying to work around. Make sprite rotate w/ the animation…thx for the hand
Here’s the link: Game Lab - Code.org

HI @michael.coyner,

I believe you are asking about the bullet directions since I see that your ship is rotating according to the arrow keys but the bullets are only shooting directly right or left. I noticed that player.getDirection only captures 0, 180, -180. So, I created a variable that captures the player rotation (lines 19 & 20 in my version) and then applied that variable to the bullet speedanddirection block (line 31).

If this isn’t what you were asking, let us know and we’ll take another look.


That works. I see how you used dir variable to track the player direction. That’s the piece I was missing…Thanks so much:)