Discuss Scratch

No-Sider
Scratcher
100+ posts

I need help trying to rotate a scene

My problem is rotation, and before you post “use the rotate or point in direction blocks”, let me explain
My project is multiple different sprites in the stage, and I want them to rotate as if they were a costume.



All of these are separate sprites, but how do I change their x, y, and directions so they end up looking rotated as one sprite
Like making the first image look like this

the sprites are rotates and moved in a way so its still relatively in the same position just in a different direction

Does anyone know what code or formula I have to use to get this?
And please, before you post an answer, make sure it works by testing it here

https://turbowarp.org/746486950/
Jlerpy
Scratcher
1000+ posts

I need help trying to rotate a scene

Try this:

In Sprite 2:
forever
go to [Sprite 1 v]
point in direction (Rotation v)
turn cw (180) degrees
move (138) steps
turn cw (90) degrees
move (16) steps
end

and in Sprite 3:
forever
go to [Sprite 1 v]
point in direction (Rotation v)
move (94) steps
turn ccw (90) degrees
end
No-Sider
Scratcher
100+ posts

I need help trying to rotate a scene

For starters, its not accurate,
as you can see the inaccuracies with Sprite 2 (the clipping thru Sprite 1) and Sprite 3 having a significant change being off Sprite 1,
Basically its not like its non rotated position.

And I also need it to be more like a formula, your code only works specifically with those positions, I'm more in need of something I can use where the x and y will vary

But good attempt tho nonetheless
Jlerpy
Scratcher
1000+ posts

I need help trying to rotate a scene

No-Sider wrote:

For starters, its not accurate,
as you can see the inaccuracies with Sprite 2 (the clipping thru Sprite 1)

The “clipping through” is a simple matter of layering. Just give Sprite 1 a
go to front

and you're good there.

and Sprite 3 having a significant change being off Sprite 1…

Ah, I see what's happened here. I moved the
change [Rotation v] by (5)
set [Rotation v] to ((Rotation) mod (361))
into Sprite 1, and that's changed the load order enough for this to eliminate a lot of that gap. Give that a try.
There IS still a small gap, but that's easily changed by adding

turn ccw (90) degrees
move (-5) steps

And I also need it to be more like a formula, your code only works specifically with those positions, I'm more in need of something I can use where the x and y will vary

To generalise it to a formula, so they can move independently, give them each two variables “RelativeX” and “Relative Y”, then you can give them:

forever
go to [Sprite 1 v]
point in direction (Rotation v)
move (RelativeX) steps
turn ccw (90) degrees
move (RelativeY) steps
turn cw (90) degrees
end

I think that should work?
No-Sider
Scratcher
100+ posts

I need help trying to rotate a scene

Jlerpy wrote:

-snip-


Thank you for your help
and about those inaccuracies, apparently yeah, changing the script that contains the “change rotation by 5”
into a different sprite really changed how inaccurate it was. I only mentioned the clipping thru part because the base direction
had the sprites no intersect with each other at all.
Jlerpy
Scratcher
1000+ posts

I need help trying to rotate a scene

Another thing is that you could do away with the Rotation variable, just having the main sprite rotate, and giving the others
point in direction ([direction v] of [Sprite1 v])
Jareddddddd
Scratcher
1000+ posts

I need help trying to rotate a scene

so heres a mathematical way to solve, though I havent tested it.
Given, you have an object at (5,6), meaning X = 5, and Y = 6
You can use this to find the hypotenuse, sqrt(61)
set [hyp v] to ((sqrt v) of (((X) * (X)) + ((Y) * (Y))))
then, you get the angle. Lets assume its 30 degrees
the new X position would be cos(30) = (x/hyp). Rearranged would be hyp*cos(30) = X.
Y would be hyp*sine(30) = Y

set [hyp v] to ((sqrt v) of (((X) * (X)) + ((Y) * (Y))))
set x to ((hyp) * ([cos v] of (angle)
set y to ((hyp) * ([sin v] of (angle)

edit: this is wrong. It assumes that the angle of (5,6) is the tangent, so around 50 degrees. This is not true, as it is not rotated.

Last edited by Jareddddddd (Oct. 17, 2022 22:19:52)

Powered by DjangoBB