Discuss Scratch

Usiah
Scratcher
12 posts

How Do I Make Somthing Rotate towards a sprite

I've Been Trying To Do This For A Month Can You Help?

ShinigamiBlacky
Scratcher
100+ posts

How Do I Make Somthing Rotate towards a sprite

uhhhm….

pointtowardsthe Sprite you want it to point to
Usiah
Scratcher
12 posts

How Do I Make Somthing Rotate towards a sprite

no rotate slowly like rotate 5 dagrees towards sprite


Usiah
Scratcher
12 posts

How Do I Make Somthing Rotate towards a sprite

btw im not dumb im a scratcher and ive been makeing games on scratch for 4 years
RokCoder
Scratcher
1000+ posts

How Do I Make Somthing Rotate towards a sprite

Make sure the custom block is set to non-refresh and use the following -

defineTurntowardssetcurrent directiontodirectionpointtowardstarget spritesettarget directiontodirectionsetdelta directiontotargetdirection-currentdirection+180mod360-180ifabsofdeltadirection<rotationspeedthenpointindirectiontargetdirectionelsepointindirectioncurrentdirection+deltadirection/absofdeltadirection*rotationspeed

The block should be called from the sprite that needs to turn. target sprite is the sprite that it needs to turn towards. current direction, target direction and delta direction are all local (this sprite only) variables. rotation speed is the speed at which you want it to turn.
TimeLordPlanet
Scratcher
500+ posts

How Do I Make Somthing Rotate towards a sprite

RokCoder wrote:

Make sure the custom block is set to non-refresh and use the following -

defineTurntowardssetcurrent directiontodirectionpointtowardstarget spritesettarget directiontodirectionsetdelta directiontotargetdirection-currentdirection+180mod360-180ifabsofdeltadirection<rotationspeedthenpointindirectiontargetdirectionelsepointindirectioncurrentdirection+deltadirection/absofdeltadirection*rotationspeed

The block should be called from the sprite that needs to turn. target sprite is the sprite that it needs to turn towards. current direction, target direction and delta direction are all local (this sprite only) variables. rotation speed is the speed at which you want it to turn.
That's a nice script, but I don't think that the
currentdirection
variable is necessary because it just renames a pre-prepared variable in the game
EDIT: Forget everything I said. I speedread sometimes, and evidently I did so when posting here

Last edited by TimeLordPlanet (July 16, 2018 13:46:44)

Usiah
Scratcher
12 posts

How Do I Make Somthing Rotate towards a sprite

Thanks!

its wierd when i get in a _=Rotaion Speed Radius of its direction. it points at me cool but not what im looking for

Last edited by Usiah (July 16, 2018 20:20:08)

RokCoder
Scratcher
1000+ posts

How Do I Make Somthing Rotate towards a sprite

Usiah wrote:

Thanks!

its wierd when i get in a _=Rotaion Speed Radius of its direction. it points at me cool but not what im looking for

Are you saying it doesn't rotate towards facing the target? If so, can you share your project as I can't see any reason why it wouldn't work.
Usiah
Scratcher
12 posts

How Do I Make Somthing Rotate towards a sprite

ok
RokCoder
Scratcher
1000+ posts

How Do I Make Somthing Rotate towards a sprite

You need to look closely at the groupings of the operators in this line -

pointindirectioncurrentdirection+deltadirection/absofdeltadirection*rotationspeed

You've grouped them differently in your project which is why it isn't working properly.

For clarity (because it's not really clear to look at) -

point in direction ( current direction + ( ( delta direction / abs of delta direction ) * rotation speed ) )

Last edited by RokCoder (July 17, 2018 06:16:11)

Usiah
Scratcher
12 posts

How Do I Make Somthing Rotate towards a sprite

Worked! i thought that was the case but coundnt see what order
Usiah
Scratcher
12 posts

How Do I Make Somthing Rotate towards a sprite

pointindirection80
ShinigamiBlacky
Scratcher
100+ posts

How Do I Make Somthing Rotate towards a sprite

Dont blockspam / Bump a forum if the poroblem is solved
alittletotheright
Scratcher
11 posts

How Do I Make Somthing Rotate towards a sprite

Instead of directly pointing in the direction, is there a way to output which way it needs to turn?

Nvm I got it. Thanks for the scripts.

Last edited by alittletotheright (Dec. 1, 2021 15:05:52)

bigbrainfishperson
New Scratcher
3 posts

How Do I Make Somthing Rotate towards a sprite

so I followed this code and while it does work it doesn't rotate as slow as I want it to. I probably did something wrong though so here's my project if someone wants to look through it and help me. https://scratch.mit.edu/projects/632454583/ . the thing that is supposed to turn is the grey tanks turret.

Last edited by bigbrainfishperson (Jan. 23, 2022 06:32:30)

Jbear_
Scratcher
1000+ posts

How Do I Make Somthing Rotate towards a sprite

bigbrainfishperson wrote:

so I followed this code and while it does work it doesn't rotate as slow as I want it to. I probably did something wrong though so here's my project if someone wants to look through it and help me. https://scratch.mit.edu/projects/632454583/ . the thing that is supposed to turn is the grey tanks turret.
Please don’t necropost, make your own topic
JulleBulle100
Scratcher
2 posts

How Do I Make Somthing Rotate towards a sprite

Usiah wrote:

Thanks!

its wierd when i get in a _=Rotaion Speed Radius of its direction. it points at me cool but not what im looking for
I think you need to set the rotation speed to something first
supa-panda
Scratcher
100+ posts

How Do I Make Somthing Rotate towards a sprite

Please don’t necropost, make your own topic
the98phases
Scratcher
8 posts

How Do I Make Somthing Rotate towards a sprite

doesnt work for scratch 3.0 @RokCoder

Powered by DjangoBB