Discuss Scratch

MegaGiacomo
Scratcher
5 posts

POINT SPRITE TOWARDS THE DIRECTION IN WICH IT'S MOVING

Hi everyone, in this project I have the main sprite pointing toward the mouse pointer. I need to get rid of the mouse because I want to use a joystick and buttons setup.

Is there a way to have the sprite pointing toward the direction in which it's moving?

Here is the link to the project

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

THANKS EVERYONE
Catchat2
Scratcher
73 posts

POINT SPRITE TOWARDS THE DIRECTION IN WICH IT'S MOVING

I modified your code.

https://turbowarp.org/editor?project_url=https://unlisted.gantzos.com/cached/643d69c8a11bb0116bfdf034

You can explain to me in more detail if you want the ship to move in a different way or not.

Last edited by Catchat2 (April 17, 2023 15:51:12)

CustomBlockMaker
Scratcher
25 posts

POINT SPRITE TOWARDS THE DIRECTION IN WICH IT'S MOVING

MegaGiacomo wrote:

Hi everyone, in this project I have the main sprite pointing toward the mouse pointer. I need to get rid of the mouse because I want to use a joystick and buttons setup.

Is there a way to have the sprite pointing toward the direction in which it's moving?

Here is the link to the project

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

THANKS EVERYONE
If you want to make a sprite point toward its next movement position, you can create a new sprite that stays hidden, and is always in front of the player. Then you can just put a point to new sprite.

Is this what you mean?
Gamergalaxy689
Scratcher
100+ posts

POINT SPRITE TOWARDS THE DIRECTION IN WICH IT'S MOVING

since you have a WASD movement system, I'd just do:
if <key [w v] pressed?> then // for up movement
point in direction (0 v)
end
and just do it for all the main cardinal directions.
for the diagonal directions, you could do:
if <<key [w v] pressed?> and <key [d v] pressed?>> then // for northeast movement
point in direction (45 v)
end

Last edited by Gamergalaxy689 (April 17, 2023 16:12:54)

10data10
Scratcher
100+ posts

POINT SPRITE TOWARDS THE DIRECTION IN WICH IT'S MOVING

Here’s another idea from the workaround guide. https://scratch.mit.edu/discuss/topic/611582/?page=1#post-6382802

define point towards x: (target x) y: (target y)
point in direction ([atan v] of (((target x) - (x position)) / ((target y) - (y position)))
if <(target y) < (y position)> then
turn cw (180) degrees
end

Point towards x: ((speed x) + (shake dx)) y:(((speed y) + (shake dy))
change x by ((speed x) + (shake dx))
change y by ((speed y) + (shake dy))


To use this in your project you’d need to combine the move x and move y custom blocks into one block and make the call to Point towards before actually changing the X and Y positions.

So now you have several suggested solutions to pick from.


MegaGiacomo
Scratcher
5 posts

POINT SPRITE TOWARDS THE DIRECTION IN WICH IT'S MOVING

Catchat2 wrote:

I modified your code.

https://turbowarp.org/editor?project_url=https://unlisted.gantzos.com/cached/643d69c8a11bb0116bfdf034

You can explain to me in more detail if you want the ship to move in a different way or not.

Thanks, I've used your code but I've switched to the arrows for directions and kept wasd for movement only.

Do you know if there's a way to have the sprite rotate smothly?
Catchat2
Scratcher
73 posts

POINT SPRITE TOWARDS THE DIRECTION IN WICH IT'S MOVING



Thanks, I've used your code but I've switched to the arrows for directions and kept wasd for movement only.

Do you know if there's a way to have the sprite rotate smothly?


Here is another modification.
https://turbowarp.org/editor?project_url=https://unlisted.gantzos.com/cached/643dc4dd58428c0099083eee
Again, tell me if you wanted the movement in another way.

Thanks.

Last edited by Catchat2 (April 17, 2023 22:15:08)

09878901234321
Scratcher
500+ posts

POINT SPRITE TOWARDS THE DIRECTION IN WICH IT'S MOVING

If I'm understanding correctly this should work
forever
turn cw ((5) * (<key [right arrow v] pressed?> - <key [left arrow v] pressed?>)) degrees
end

Last edited by 09878901234321 (April 17, 2023 22:15:33)

MegaGiacomo
Scratcher
5 posts

POINT SPRITE TOWARDS THE DIRECTION IN WICH IT'S MOVING

Catchat2 wrote:


Thanks, I've used your code but I've switched to the arrows for directions and kept wasd for movement only.

Do you know if there's a way to have the sprite rotate smothly?


Here is another modification.
https://turbowarp.org/editor?project_url=https://unlisted.gantzos.com/cached/643dc4dd58428c0099083eee
Again, tell me if you wanted the movement in another way.

Thanks.
Works great! Tahnkyou!
CustomBlockMaker
Scratcher
25 posts

POINT SPRITE TOWARDS THE DIRECTION IN WICH IT'S MOVING

MegaGiacomo wrote:

Catchat2 wrote:


Thanks, I've used your code but I've switched to the arrows for directions and kept wasd for movement only.

Do you know if there's a way to have the sprite rotate smothly?

Here is another modification.
https://turbowarp.org/editor?project_url=https://unlisted.gantzos.com/cached/643dc4dd58428c0099083eee
Again, tell me if you wanted the movement in another way.

Thanks.
Works great! Tahnkyou!
Smooth turning: In @griffpatch's maze pathfinding, he explains one technic to make a sprite smooth-turn
https://youtu.be/0faPPgOT–E?t=833

Powered by DjangoBB