# Rotation and aiming help needed!

Hello! I wanted to develop some kind of twin-stick shooter (top down). The way I decided it would be best would be that the player can use A and D to rotate left or right, and W to move in that direction. They can also use J and L to rotate some kind of projectile launcher and use Space to fire it at that angle.

Is there any way in which I can modify and rotate the player sprite, without having to hand animate it?
Also is there any bit of code I can use to make the player move at a certain VX and VY to make it match up with the angle the player decided using A and D, and the same for the projectileâ€™s angle?

Thanks.

Sprite utils extension can be used for moving the playing at angle and speed.
For rotating, use pxt-scaling
(Both are on my list of extensions)

1 Like

Thanks. I tried something like this: https://makecode.com/_H41U1WdAb3s7

You use A and D to rotate and W to move. But it failed HORRIBLY. Any help would be appreciated. (The little curve is the head of the player.)

1 Like

Alright I think this is what you want:

What I did was that I kept the original image: (as a variable)

And then when I needed to change the rotation I would copy the image before rotating:

This makes it slightly â€śbetterâ€ť so that 90, 180, 270, and 0 are nice and straight. Rotating an already-rotated image (how the sprite-transformation extension does it) â€śloses quality.â€ť

Also, the moving doesnâ€™t work cause the `set [sprite] velocity at angle [num] speed [num]` accepts radians although you were working in degrees. Thankfully, there is a block to convert degrees to radians. (And vice versa, since this extension works in radians, unlike the scaling extension which works in degrees) Also, to make it so that it moves in the direction of the head, you would subtract (or add) 180 degrees.

And then I changed it so that pressing the left key subtracts degrees instead of adding degrees so it actually turns left instead of right and vice versa.

Code:

2 Likes

This is absolutely brilliant! Thanks a bunch.

1 Like

WOW I now can use guns finally MWAHAHAAH