Discuss Scratch

Oisthebestletter
Scratcher
100+ posts

Smooth Rotation

Hey! I was making a game and was sick of the regular “point towards” block that we have. I needed something smoother that lags a bit behind. So I watched this tutorial and put it in this project, but I got stuck on the part with the “funky animation” that the turret does. See for yourself!
wavewavegame
Scratcher
26 posts

Smooth Rotation

It seems to be working fine.
Oisthebestletter
Scratcher
100+ posts

Smooth Rotation

wavewavegame wrote:

It seems to be working fine.
No, if you go to the left side of the screen and put your mouse in the bottom of the screen, then go to the top, it makes it do a weird spin thing.
wavewavegame
Scratcher
26 posts

Smooth Rotation

That part was intentional in the code, I am unsure on how to prevent objects from flipping in scratch.
Oisthebestletter
Scratcher
100+ posts

Smooth Rotation

wavewavegame wrote:

That part was intentional in the code, I am unsure on how to prevent objects from flipping in scratch.
DID YOU EVEN WATCH THE VIDEO-
Oisthebestletter
Scratcher
100+ posts

Smooth Rotation

Oisthebestletter wrote:

wavewavegame wrote:

That part was intentional in the code, I am unsure on how to prevent objects from flipping in scratch.
DID YOU EVEN WATCH THE VIDEO-
Sorry, i get fired up sometimes
Im_here_for_fun
Scratcher
10 posts

Smooth Rotation

though I don't know much about calculus, the problem could be the arctangent block, however I doubt it, because the problem isn't visible when the cursor is moved slowly. I don't think it's that there's something different between your project and the one in the tutorial, it's that the spaceship moves too slowly to make the turret spin in the opposite direction, while using the mouse allows for faster movements. I honestly have no idea how to fix it.
Oisthebestletter
Scratcher
100+ posts

Smooth Rotation

Im_here_for_fun wrote:

though I don't know much about calculus, the problem could be the arctangent block, however I doubt it, because the problem isn't visible when the cursor is moved slowly. I don't think it's that there's something different between your project and the one in the tutorial, it's that the spaceship moves too slowly to make the turret spin in the opposite direction, while using the mouse allows for faster movements. I honestly have no idea how to fix it.
Oh, ok. And by the way, it's trigonometry, not calculus
TheCreatorOfUnTV
Scratcher
1000+ posts

Smooth Rotation

Deleted

Last edited by TheCreatorOfUnTV (Jan. 21, 2025 03:22:42)

nembence
Scratcher
100+ posts

Smooth Rotation

The problem is that you can cross the north-south line in a way that there are no checks in the regions above and below the line. (eg. by moving almost horizontally near the turret or by moving very fast)
A more reliable way to check crossing the line is using the difference between targetAngle and lastAngle. If the difference is bigger than 180 degrees, then the target crossed the line.
This works because for every two positions there are two angles between them that add up to 360°, so one of them is bigger and the other is smaller than 180°. The difference measures the angle that doesn't cross the line, so if it's bigger than 180° then the smaller angle is the one that crosses the line.
s714655
Scratcher
100+ posts

Smooth Rotation

RokCoder
Scratcher
1000+ posts

Smooth Rotation

Oisthebestletter wrote:

Hey! I was making a game and was sick of the regular “point towards” block that we have. I needed something smoother that lags a bit behind. So I watched this tutorial and put it in this project, but I got stuck on the part with the “funky animation” that the turret does. See for yourself!
This is a nice solution to your problem that allows you to also pass in the speed of rotation -

defineTurntowardsx:xy:ywithspeed:speedsettarget directiontoatanofx/y+180*y<0setdelta directiontotargetdirection-direction+180mod360-180ifabsofdeltadirection<speedthenpointindirectiontargetdirectionelsepointindirectiondirection+deltadirection/absofdeltadirection*speed
Oisthebestletter
Scratcher
100+ posts

Smooth Rotation

RokCoder wrote:

Oisthebestletter wrote:

Hey! I was making a game and was sick of the regular “point towards” block that we have. I needed something smoother that lags a bit behind. So I watched this tutorial and put it in this project, but I got stuck on the part with the “funky animation” that the turret does. See for yourself!
This is a nice solution to your problem that allows you to also pass in the speed of rotation -

defineTurntowardsx:xy:ywithspeed:speedsettarget directiontoatanofx/y+180*y<0setdelta directiontotargetdirection-direction+180mod360-180ifabsofdeltadirection<speedthenpointindirectiontargetdirectionelsepointindirectiondirection+deltadirection/absofdeltadirection*speed
Thanks!

Powered by DjangoBB