Finding Horizontal/Vertical Distance Between Two Points in Scratch 3.0

Click For Summary
SUMMARY

The discussion focuses on calculating the horizontal and vertical distances between the center of a shooter sprite and the end of the gun barrel in Scratch 3.0. The user identifies specific distances when the sprite is facing 90º, with an X distance of 105 pixels and a Y distance of 45 pixels. To find the distances for other angles, the user suggests using the Pythagorean theorem to determine the hypotenuse, which represents the distance from the origin to the muzzle of the gun. This approach allows for accurate bullet trajectory in the game.

PREREQUISITES
  • Understanding of Scratch 3.0 programming environment
  • Basic knowledge of trigonometry, specifically right triangles
  • Familiarity with Pythagorean theorem application
  • Concept of sprite rotation and its impact on coordinates
NEXT STEPS
  • Research how to implement trigonometric functions in Scratch 3.0
  • Learn about Scratch 3.0's coordinate system and sprite rotation
  • Explore advanced techniques for calculating distances in game development
  • Investigate methods for creating realistic projectile motion in Scratch 3.0
USEFUL FOR

This discussion is beneficial for game developers using Scratch 3.0, particularly those creating shooting mechanics and requiring precise control over sprite movements and trajectories.

Kizza23
Messages
1
Reaction score
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: 146
  • Background (1).png
    Background (1).png
    11.8 KB · Views: 132
Mathematics news on Phys.org
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?
 

Similar threads

Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
8K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
9
Views
5K
Replies
20
Views
4K
Replies
9
Views
3K