I’m working on a top-down shooter, and right now, I finished the movement system. When you press an arrow key, the player will rotate in that angle. How to make the same thing when firing bullets? Right now, they fire in 4 directions, but not in the same direction you move in. Please help me. Thanks.
When you create the bullets, set the angle of the bullet to be the same as the player current angle and move each bullet toward it own angle.
So the event could look something like this:
create object bullet
Do = player.Angle() to angle of bullet
Move bullet (very important to use For each object event):
For each object bullet
no condition : Add to bullet a force, angle: bullet.Angle() degrees and length: 100 pixels
Thanks for trying to help, but it didn’t work. It’s even more weird. When I add this Player.Angle() event, all bullets move in just one direction, no matter where I move the player, and when I add the second event you said, it looks like a waterfall. Here is a screenshot of what I have done (without your events): prntscr.com/betlbc
My exact problem is:
-when I fire while moving right, the bullets go down
-when I fire while moving left, the bullets go up
-when I fire while moving down, the bullets go left
-when I fire while moving up, the bullets go right
The only thing I want to do is make them go in the right direction.
If you got time, could you please copy what I did in that screenshot above, try to make it work, and once it does work, send me a screenshot or write what you did?
I’m only guessing but try to modify the last event like so:
If it doesn’t work, here is an example I was throw together quickly, it may help to get the idea:
I tried what you did, but sadly, it didn’t work: prntscr.com/bf0zm3
And now, I just tried your example. I know that works, I already did it in some previous projects. I modified your example by adding arrow key movement and angle when you move in a direction, and the same thing happens. Bullets do not fire in the right direction.
Probably because you are using wrong degrees for angle rotation I was not aware of that. This is how degrees works in GDevelop:
Since you was happy with the rotation of your player object when using the wrong degrees, I guess the sprite is facing the wrong direction by default. You need to make sure all your sprites facing right by default on the actual images to make it work.
I have just modified my example, now it rotating and moving using the arrow keys and it works:
shoot_bullet2.zip (41.1 KB)
Oh thank you so much. I finally get it. I used pixelartor.com/ to create this sprite and I wasn’t even thinking about that direction. When I was working on the angle, I was just experimenting until I got the right angle. Now I finally figured out how it should be done. Luckily, I can just load the sprite in that site, and rotate it. Thanks for helping me!
EDIT: I’ve done it, it all works, except that I must add diagonals…uh…