MHB Finding Horizontal/Vertical Distance Between Two Points in Scratch 3.0

AI Thread Summary
To accurately position the bullet in a Scratch 3.0 game, the shooter sprite's barrel must be aligned with the bullet's trajectory based on the sprite's rotation. The X and Y distances from the sprite's center to the barrel's end vary with the angle of rotation, complicating the calculation. When the sprite faces 90º, the distances are 105 pixels horizontally and 45 pixels vertically. To find the distances for other angles, using trigonometric functions or Pythagorean theorem is suggested, as it forms a right triangle. This approach will ensure the bullet appears to exit the gun correctly regardless of the sprite's orientation.
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: 127
  • Background (1).png
    Background (1).png
    11.8 KB · Views: 110
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?
 
Thread 'Video on imaginary numbers and some queries'
Hi, I was watching the following video. I found some points confusing. Could you please help me to understand the gaps? Thanks, in advance! Question 1: Around 4:22, the video says the following. So for those mathematicians, negative numbers didn't exist. You could subtract, that is find the difference between two positive quantities, but you couldn't have a negative answer or negative coefficients. Mathematicians were so averse to negative numbers that there was no single quadratic...
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Thread 'Unit Circle Double Angle Derivations'
Here I made a terrible mistake of assuming this to be an equilateral triangle and set 2sinx=1 => x=pi/6. Although this did derive the double angle formulas it also led into a terrible mess trying to find all the combinations of sides. I must have been tired and just assumed 6x=180 and 2sinx=1. By that time, I was so mindset that I nearly scolded a person for even saying 90-x. I wonder if this is a case of biased observation that seeks to dis credit me like Jesus of Nazareth since in reality...
Back
Top