How do I attach a thing to another?

This is a problem that most of you guys have figured out but I haven’t. How do you attach a thing to another thing? I am trying to attach a Tetris Line with a Circle to make a tank turret. I can’t seem to make the Tetris Line also rotate when the circle is rotating and still have them both attached.

13 Likes

hey, to do this, you should use a little bit of trigonometry

Tetris:
Set SelfX to cos(Circle’s Angle) * Distance to Circle + X position of Circle
Set SelfY to sin(Circle’s Angle) * Distance to Circle + Y position of Circle

Hope this helps! Tag me for any other questions.
Welcome to the forum, by the way! :))

6 Likes

yeah, welcome to the forum! :wave:t2:

8 Likes

Welcome to the forum!
Yeah I think that’s how it works

6 Likes

Welcome to the HS forum!
You can find the “self x” and “self y” in “objects”

5 Likes

How do I change the code to the blocks on the Hopscotch app. I can’t seem to find SelfX or SelfY anywhere. Thanks! (I am a newbie)

@Tri-Angle

7 Likes

Once you have the block you’re looking for, they’re under the “object” set of variables


8 Likes

yup ^^^

to keep the tetris line pointing at the turret, add this code

When SelfX < CircleX
Set Angle to arctan((SelfY-CircleY)/(SelfX-CircleX))+180
End

When SelfX > CircleX
Set Angle to arctan((SelfY-CircleY)/(SelfX-CircleX))
End

check this link ^^^ for full code - this is using @/Awesome_E project builder so it will not open in Hopscotch

4 Likes

The code doesn’t seem to quite work. Can you guys check my code to find any errors?


^^^This is the problem.
I have published my project so I think you guys can see the code(look in the Tetris Line). Thanks!

5 Likes

can you send a link? i can’t seem to find your project

3 Likes

I tried to fix it, but I’m not sure how to make the gu.n stay since the angle makes the position look weird.

3 Likes

This is the link to my project: Moving Tank (Test) by WallytheQuail

4 Likes

here ^^^ i fixed your project
tag me if you have any other questions :))

(@Wally @Bobinny)

5 Likes

This topic was automatically closed after 3 days. New replies are no longer allowed.