Discuss Scratch

Xenogeneticon
Scratcher
100+ posts

get rid of faster diagonal movement

Hey guys, I am making a top-down shooter game, but if you press two different movement keys (like arrow keys) that make the player go diagonally, it also makes the player go faster. I do not know how to fix this, do any of you guys have any helpful suggestions? This is my current code:

forever
if <key [up arrow v] pressed?> then
change y by (3)
end
if <key [down arrow v] pressed?> then
change y by (-3)
end
if <key [left arrow v] pressed?> then
change x by (-3)
end
if <key [right arrow v] pressed?> then
change x by (3)
end
end

This is a scrolling game so x and y would be replaced by scroll x and scroll y, but I just wrote x and y to make it simpler.

Last edited by Xenogeneticon (Jan. 2, 2024 21:20:45)

Soliscrat
Scratcher
68 posts

get rid of faster diagonal movement


My Version

Last edited by Soliscrat (Jan. 2, 2024 22:03:24)

Xenogeneticon
Scratcher
100+ posts

get rid of faster diagonal movement

On a comment inside the project it says “replace 5 with your speed,” and on the block it is 11 multiplied by a big operator. does it mean 11?
Soliscrat
Scratcher
68 posts

get rid of faster diagonal movement

oh oops I changed it last seccond, but yeah the 11 is supposed to be the speed
pika_boo
Scratcher
100+ posts

get rid of faster diagonal movement

Another way is you could use direction (pointing towards mouse) and do move_ steps, as this will be the same distance when going in any direction, and will result in significantly less code.

Last edited by pika_boo (Jan. 3, 2024 09:20:56)

Homeless_Mario68
Scratcher
89 posts

get rid of faster diagonal movement

define move in angle (angle) with speed of (speed)
go to x: ((x position) + (([sin v] of (angle)) * (speed))) y: ((y position) + (([cos v] of (angle)) * (speed)))

::#ffffff
::#ffffff




forever{
if <<key [up arrow v] pressed?> and <key [right arrow v] pressed?>> then

move in angle (45) with speed of (3)

else
other controls here::motion
end
}::control

this cutom block should have the same effect as the
point in direction (45)
move (3) steps
except that you dont have to change your sprites direction

Last edited by Homeless_Mario68 (Jan. 3, 2024 13:50:11)

mariofan1767
Scratcher
7 posts

get rid of faster diagonal movement

bro I went on here because if you go diagonally on a wall that has collision it goes through the wall.

Powered by DjangoBB