Discuss Scratch

littlebigkitten
Scratcher
1 post

Smooth Top-Down turning

So basically I want to make it so that if you are facing one direction, and turn to another, instead of snapping, you turn smoothly but without using alot of unnecessary code. You move with the arrow keys and whatever direction you press, you instantly snap to. It's a top-down game.
anuntitledscratcher
Scratcher
28 posts

Smooth Top-Down turning

I hope this works for you!

when green flag clicked
forever
if <key [up arrow] pressed?> then
change [yVel] by (1.5)
end
if <key [down arrow] pressed?> then
change [yVel] by (-1.5)
end
if <key [right arrow] pressed?> then
change [xVel] by (1.5)
end
if <key [left arrow] pressed?> then
change [xVel] by (-1.5)
end
set [xVel] to ((xVel) * (0.9))
change x by (xVel)
set [yVel] to ((yVel) * (0.9))
change y by (yVel)
end

If you want something slower or faster you can change around the values.
anuntitledscratcher
Scratcher
28 posts

Smooth Top-Down turning

Now that I think about it, the code only does movement, and doesn't really rotate, sorry about that.
Although, I think that a good way to create smooth rotation would be to simply make the player point to the mouse cursor, in combination with WASD keys for movement, it's pretty easy to control.

But, anyway good luck on your game!

Powered by DjangoBB