Can someone explain why the stuff I put together doesn't work

This
Intended effect: Sprite turns 5 degrees clockwise until it's pointing at the mouse while moving 2 steps constantly
Actual effect: sprite go spin (doesnt move btw, it just spins at the center)

I think it's because you don't understand what untitled script pic is. That value is not a direction, instead it's the x position on the stage of the sprite's rotation point (where it rotates around). I think you might be looking for the untitled script pic (77) block, which reports the direction the sprite is facing.

There are also another thing that is a problem, it will most likely keep rotating in circles, because rotating 5 degrees at a time will most likely result in it skipping the direction of the mouse. You should instead rotate by 1 degree, and round both the sprite direction and the direction to mouse-pointer.

Is there a way to make it turn counter-clockwise when doing so makes the sprite point at the mouse faster?

Another thing: Now it works but it turns away when close to the mouse.

can you please show the project?

additionally, in snap, right click the blocks and select script pic to get a picture of them. you can drag and drop these pictures from the forum into snap to get the blocks.

This user is new, so they can't attach pictures quite yet (I have had the same problem).

Yes. Here is an example script:


The second predicate in the "or" block accounts for the fact that 359 degrees is the same as -1 degrees.

This is likely because Snap*!* does not report fractional degree values for "direction to mouse pointer". As the sprite moves closer to the mouse, this fractional difference may become a full degree difference. Because the sprite would only turn one direction, it wouldn't always just compensate for the 1 degree - instead, it would turn the other direction 359 degrees.

incorrect:
untitled script pic1

That's why I suggested

or keep the 5 degree turning and round both to the nearest multiple of 5

Correction: direction to mouse pointer does not report a fractional value. So as long as you are starting at an integer direction and are turning by 1 degree each time, the script will work the way I said it would.

So my script should really have a round block OR set direction to 90 degrees at the start.

huh. so it doesn't
JSFunctions script pic

Sorry about the confusion, I made the (incorrect) assumption that because "direction to mouse pointer" did not report fractional values, "direction" would work the same. I will update my original reply.

whoops. I joined much before smart script pics (snap 6-7, i think) so I never had this issue since I didn't use script pics as much.

i joined around 6.8.1 or 6.9.0 i think

Since rotation values greater than 1 cause the sprite to sometimes have a seizure due to never being able to point exactly at the mouse, is there a way to do something simpler than making it turn only 1 degree whenever its direction is 3 or less degrees off? (which causes it to repeatedly turn 4 degrees left and right)

If I understand you correctly, what you really want is to have the sprite turn faster. By using the warp block and a repeat 3 we can make it move 3 degrees quickly while not overshooting (note that the if statement makes sure you don't move 3 degrees if you really should be moving 1 or 2).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.