Discuss Scratch

KubaloPL123
Scratcher
14 posts

Moving Diagonal Problem

https://scratch.mit.edu/projects/222056765/

when you move in any direction (not diagonal) your speed is OK
when you move in any direction (diagonal) your speed is doubled
how do i fix it?
Garamol56
Scratcher
100+ posts

Moving Diagonal Problem

Well, your script says that when
<key [up arrow v] pressed?>
the sprite should move 10 steps (adding 10 to speed variable)
AND, when
<key [right arrow v] pressed?>
the sprite should move ANOTHER 10 steps (adding ANOTHER 10 to speed variable)
10+10 = 20: so it doubles the speed
gor-dee
Scratcher
1000+ posts

Moving Diagonal Problem

The speed isn't actually doubled it's about x1.414. (the diagonal of a square is 1.414 x the length of one side)
To fix it you could use
point in direction ( v)
move () steps
but you would need a different way of moving
You could do
 
if <key [up v] pressed?> then
if <<key [left v] pressed?> or <key [right v] pressed?>> then


change y by ((10) * ([cos v] of (45)))

else
change y by (10)
end
end

and so on

Last edited by gor-dee (May 10, 2018 15:00:17)

Luca3Dartist
Scratcher
3 posts

Moving Diagonal Problem


Last edited by Luca3Dartist (Jan. 25, 2022 07:03:25)

tinyboy4556
Scratcher
1 post

Moving Diagonal Problem

gor-dee wrote:

The speed isn't actually doubled it's about x1.414. (the diagonal of a square is 1.414 x the length of one side)
To fix it you could use
point in direction ( v)
move () steps
but you would need a different way of moving
You could do
 
if <key [up v] pressed?> then
if <<key [left v] pressed?> or <key [right v] pressed?>> then


change y by ((10) * ([cos v] of (45)))

else
change y by (10)
end
end

and so on

Thanks, it really helped.

Powered by DjangoBB