Finding Horizontal/Vertical Distance Between Two Points in Scratch 3.0

In summary, The speaker is creating a game on Scratch 3.0 and needs the bullet to appear to be coming out of the gun. They are facing issues with finding the X and Y distances of the end of the barrel from the centre of the shooter sprite due to Scratch not allowing diagonal distances. The speaker knows the distances for when the shooter sprite is facing 90º but is unsure about the distances for other angles and wonders if a special formula is needed. Additionally, it is suggested to use Pythagoras' theorem to find the distance from the origin to the muzzle.
  • #1
Kizza23
1
0
I am making a Scratch 3.0 game. The shooter sprite is holding a gun slightly off-centre (see images), and I need the bullet to go to the end of the barrel of the gun before traveling forward (as so it would appear the bullet it leaving the gun). The issue is, to do this, I need to find the X and Y distance of the end of the barrel from the centre of the shooter sprite (Scratch doesn't let you use diagonal distances 😡). The X and Y distances change as the sprite rotates.

I know if the shooter sprite is facing 90º (right angle), the X distance to the gun is 105 pixels, and the Y distance is 45 pixels.

The computer always knows what direction the shooter sprite is facing.

What about the distances for all the other angles the shooter sprite is facing? Do I need a special formula?

View attachment 8942
View attachment 8943
 

Attachments

  • Background (2).png
    Background (2).png
    12.2 KB · Views: 60
  • Background (1).png
    Background (1).png
    11.8 KB · Views: 57
Mathematics news on Phys.org
  • #2
Looks like a right triangle is formed in each case you've shown ... couldn't the distance from your set origin to the muzzle (the hypotenuse) be found using Pythagoras?
 

Related to Finding Horizontal/Vertical Distance Between Two Points in Scratch 3.0

1. How do I find the horizontal/vertical distance between two points in Scratch 3.0?

To find the horizontal/vertical distance between two points in Scratch 3.0, you can use the "Distance to" block under the "Sensing" category. This block will give you the distance in pixels between the two points.

2. Can I find the horizontal/vertical distance between two points in Scratch 3.0 using coordinates?

Yes, you can use the "Distance to" block and input the coordinates of the two points to find the horizontal/vertical distance between them. Make sure to use the correct coordinate system (e.g. Scratch's coordinate system starts at the center of the stage).

3. Is there a way to find the horizontal/vertical distance between two points without using the "Distance to" block?

Yes, you can use the "Set X to" and "Set Y to" blocks under the "Motion" category to set the X and Y positions of the two points, and then use the "Difference" block under the "Operators" category to find the difference between the two positions. This will give you the horizontal/vertical distance between the two points.

4. Can I use the horizontal/vertical distance between two points in Scratch 3.0 to create games or animations?

Yes, the horizontal/vertical distance between two points can be used in various ways to create games or animations in Scratch 3.0. For example, you can use it to calculate the speed of a moving object or to make characters follow a specific path.

5. How can I use the horizontal/vertical distance between two points to make my Scratch 3.0 project more interactive?

You can use the horizontal/vertical distance between two points to create interactive elements in your project. For instance, you can use it to trigger certain actions when the distance between two points reaches a specific value, or to create a mini-game where the player has to move objects to a specific distance from each other.

Similar threads

Replies
1
Views
2K
Replies
7
Views
7K
  • Precalculus Mathematics Homework Help
Replies
20
Views
2K
  • Introductory Physics Homework Help
Replies
5
Views
4K
  • General Math
Replies
1
Views
2K
  • Introductory Physics Homework Help
2
Replies
35
Views
3K
  • Introductory Physics Homework Help
Replies
9
Views
4K
Back
Top