This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-10-18 13:35:16

websites
New Scratcher
Registered: 2012-10-18
Posts: 9

Keeping sprite A in position over sprite B as sprite B rotates

How do I code keeping a sprite (A) in position over the left end of rectangular shaped sprite (B) as (B) rotates left or right. Say sprite B is a star ship and sprite A is a turret overlaid sprite B. I want sprite A to be able to 'orbit' sprite B and visually remain in position as sprite B rotates. Sprite B does not move, it only rotates.

Offline

 

#2 2012-10-18 13:41:07

subzerostig
Scratcher
Registered: 2010-09-08
Posts: 100+

Re: Keeping sprite A in position over sprite B as sprite B rotates

Try setting the center rotation to make it work. Then simply set it to keep to the same rotation as A


There are 10 types of people people in this world, those that understand binary and those that do not: My latest Project: Present catcher V2                          06/12/2012

Offline

 

#3 2012-10-18 13:46:55

websites
New Scratcher
Registered: 2012-10-18
Posts: 9

Re: Keeping sprite A in position over sprite B as sprite B rotates

how? I am really new to this.

Offline

 

#4 2012-10-18 13:58:19

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Keeping sprite A in position over sprite B as sprite B rotates

In the costume/paint editor, there is a crosshair/plus sign that you can click and then select somewhere on the costume to change the center/rotation point of the sprite.  smile

Offline

 

#5 2012-10-18 19:19:18

websites
New Scratcher
Registered: 2012-10-18
Posts: 9

Re: Keeping sprite A in position over sprite B as sprite B rotates

I found that but it sets the rotation center for the sprite it does not set a point at which it will then follow another sprite, as I described.

Offline

 

#6 2012-10-18 23:02:41

websites
New Scratcher
Registered: 2012-10-18
Posts: 9

Re: Keeping sprite A in position over sprite B as sprite B rotates

OK I found my answer

when [right-arrow v] key pressed
go to front
set [b_cos v] to <[cos v] of angle>
set [b_sin v] to <[sin v] of angle>
set [b_dy v] to <(b_sin) * (b_hyp)>
set [b_dx v] to <(b_cos) * (b_hyp)>
go to x: (b_dx) y: (b_dy)
stop script
Where:
angle is the measurement in degrees that sprite B is facing.
b_cos is the cosine of angle
b_sin is the sine of angle
b_hyp is the pixel distance from the center point of Sprite B to the center point of Sprite A
A press of the right arrow rotates Sprite B 1 degree to the right
A press of the left arrow rotates Sprite B 1 degree to the left

I hope this helps others.

Offline

 

#7 2012-10-18 23:22:39

thebriculator
Scratcher
Registered: 2011-07-11
Posts: 500+

Re: Keeping sprite A in position over sprite B as sprite B rotates

or more simply,

go to x: (([sin v] of ([direction v] of [arm v])) * (length)) y: (([cos v] of ([direction v] of [arm v])) * (length))
be sure your rotating thing is at (0,0)
if not, you will need to adjust accordingly

Last edited by thebriculator (2012-10-18 23:28:37)


.     http://tiny.cc/2cwgpw    http://tiny.cc/viwgpw    http://tiny.cc/iwwgpw

Offline

 

#8 2012-10-19 11:10:37

websites
New Scratcher
Registered: 2012-10-18
Posts: 9

Re: Keeping sprite A in position over sprite B as sprite B rotates

Thanks that works very well.

Offline

 

Board footer