Hello, I'm trying to create a proof of concept for a snowball rolling game using Snap!
Currently, I can't find a way to calculate the distance needed for the snowball to grow while not overlapping the character sprite.
My project can be viewed at the link below. The controls are in the "Sprite" sprite, and the troublesome code is found in the "Snowball" sprite when the green flag is clicked.
Use BeetleBlocks(or just simply hack openGL and mod it)
So it's a limitation with Snap? There isn't anything I can try in the program to keep it 2D?
Of course, you can! You can calculate the distance using x and y positions.
EDIT: I looked in your code. Could you please explain more about your game? You seem to be using x and y positions already.
Certainly. I'm trying to make sure that as the snowball grows, the player is always behind it, just like real life. The game itself is similar to "Snowball.io" but in 2D, so look at footage of that game if you'd like.
I'm aware I can add the X and Y positions of the sprite, and sin or cos of the player's direction (respectively) to keep the snowball in front of them in an orbit. The problem comes with constantly scaling the radius of its orbit around the player with the snowball's size. I circled a snippet of my code where I think I could put this number once I find the proper way to calculate it. My first formula was the square root of the size, times 2, but that didn't seem to work.
Is that clearer?
Many comments here...
- First, "size" is not a length, is a proportion (a percentage) of the original size. It can be 100%, 50%, 200%... So you have to use the length values (width, height...) and also size to recalculate them.
- Be careful, that "size" is a 1-D proportion. A 200% costume will be twice as wide and as hight. Really it will be a 400% of surface. So, you don't need "sqrt"
- And also, you need the distance between both sprites. So you need to check both sizes (and lenghts)
- About angles. Your angles runs ok, because sin and cos properties... but maybe is better to use a "general transformation" (use the same angle calculation on both sides). The general rule is [Cartesian angle = 90 - Snap!Angle]. But here, that you have a correction (+90) because your costume orientation, it will be (180 - snapAngle)
- And other issue you have. There is some problem with your "Sprite costume". Maybe with your paint editor? If you check it, you will see reporters return height=64 and width=32... but this costume is wider!! You only have to edit this costume and save it (ok). Then you will get the real values (height=16 and width=32).
That's all! Remember to "reedit" your costume and play with something like this...
I do not know where to find the game you are talking about what @jguille2 has pointed out good facts and helped you already.
Thank you! This seems to work a lot better. My sprite sizes might have been off due to me giving myself a lot of area in my original art editor. However, when I shrunk it down to its actual size nothing seemed to change. After testing, 200 was still the most consistent number to divide (height of costume) * size by, hopefully this effect won't be as difficult to implement in full-fledged game engines like Unity.
Just for my own clarity, you divide by 200 because, after multiplying by 'size', you've turned the distance value into a percentage. So, the 200 = 2 * 100, where the 100 part turns the value back into an actual distance, and the 2 part divides it in half. Doing this for both sprites puts the distance as half the size of each sprite added together. Right?