Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Problem with some math

Atoa

Member

I having some problems with math in rgss.

It's a bit hard to explain, so i will use this example:
Novo(a)%20Imagem%20de%20Bitmap2_2.PNG

the red dot is sprite 1, and the blue dot is the sprite 2. I want to set the purple dot (sprite 3) alingned with them. at a set distance from sprite 2 (the dark green line).

I have sprite 1 x/y postion, sprite 2 x/y position and the distance.

Any help about how i can get sprite 3 x/y position?
 

Star

Sponsor

Here's an example, not sure how to make a formula

Sprite 1 - x = 10
Sprite 1 - y = 15
Sprite 2 - x = 20
Sprite 2 - y = 30

Sprite 2x - Sprite 1x = 10
Sprite 2y - Sprite 2y = 15

Now find the relation between their distance with the Red and Blue dot

The distance between the red and blue dot is 100% now find the percentage of the blue and purple dot. If the distance is 200ft for the red and blue dot and the distance for blue and purple dot is 50ft take 200 and divide it by 50 to get 4 then use this formula 4 * x = 100 or x = 100/4 to get your percentage which in this case is 25%
if the distance between the blue dot and purple dot is 50% multiply the x10 and y15 by .5 or 50% to get x5 and y7.5 and add them to sprite 2 x and y to get sprite 3 x 25 y 37.5.
if the distance between the blue dot and purple dot is 150% multiply the x10 and y15 by 1.5 or 150% to get x15 and y22.5 and add them to sprite 2 x and y to get sprite 3 x 35 y 52.5.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top