POCKETS
Terrarian
I feel like this one may be more difficult than it sounds. Finding an example of an even or random spread of projectiles, that originate from the center of the weapon, is actually quite easy. So, I'm taking that code as an example to learn from.
I wanted to post what I've learned from the code so far, so that I can understand where to go from there.
OK, so here's the projectile spread code (this is a variation of what I'm currently using) -
What I've learned from this so far -
To begin with, the for loop is basically telling the game how many projectiles to spawn.
Projectile.NewProjectile is responsible for spawning a new projectile. The position.X and Y tell the projectile where to spawn. In this case, the center of the weapon - more specifically, the center of the weapon as you rotate the weapon around 360 degrees - has to do with vectors. The speed X and Y also have to do with vectors, and I'm seriously lacking knowledge on this subject (I do know it has to do with direction and magnitude). The type is just the type of projectile (in my case mod.ProjectileType<modProjectile>()). The damage here can be set independently of the weapon's damage (basically, it will ignore weapon damage and bonuses) - if I'm wrong about this, just let me know, but this is how it was explained to me. Knockback is self explanatory. The player.whoAmI (I believe) just sets who shot it?? (not sure on this one).
If I'm wrong about any of this, please feel free to correct me.
Obviously, these new projectiles will always originate from the center of the weapon, so that's not what we want.
I feel like this problem has to do with vectors, from what little I know of them, and from what I've seen in very basic YouTube video explanations on the subject.
Now, here's where I try to explain how stupid I am (this is more or less just thinking out loud) --
Alright, so let's say that when the weapon is rotated (which can rotate 360 degrees), it's sprite (or image) has to move around a center point (we'll call this X0 and Y0). Obviously, the weapon sprite doesn't rotate around it's own center, it has to be rotating around some other point (perhaps the player?). Therefore, the sprite of the weapon must be offset from that point by a certain amount. So, if it's offset from the player's center, this make perfect sense, and I believe this has to do with vectors.
So, if I drew a line from X0, Y0 to Y10 and placed a point at each spot, then rotated that line using X0, Y0 as an axis, rotating by 90 degrees would eventually get me a line from X0, Y0 to X10 (or -X10, depending on which way you rotated). OK, so with that in mind, I think of a weapon's rotation around the player's center the same way. Therefore, using the above example, shooting a projectile straight up in the air, the projectile would originate from Y10.
I should point out that I have no idea if projectiles in Terraria use the player as the rotation point for the firing of said projectiles. It would make sense, but from what I've seen in the code, it may have to do with the weapon, so maybe the player's center is just a reference for the weapon and it's firing center? Just curious.
If I want to offset a projectile's originating position, I can't just change the center of rotation, as the projectile's firing position would appear to change as the weapon was rotated around 360 degrees (this is why offsetting from position.X and position.Y in NewProjectile won't work). There must be a way to still use the player's center (or whatever the weapon is using as it's rotational axis), and then just rotate the line slightly using that axis, making the projectile appear to be originating from an offset of the weapon's firing center. Then, rotate the projectile itself by a small amount to account for the change (otherwise, it would still appear to be shooting at an angle from the weapon itself).
Alright, so now that I've completely embarrassed myself, I will defer to the more experienced users to lend me a helping hand on this one. If I'm even close, I'd be surprised, but logically speaking, my explanation does make sense, at least in my head. Again, I have no clue if Terraria handles projectiles this way, so please feel free to correct me.
I'm the type of person that has to know how things work, so I can't just ask for code and be on my way. I need to know how things are functioning
I wanted to post what I've learned from the code so far, so that I can understand where to go from there.
OK, so here's the projectile spread code (this is a variation of what I'm currently using) -
C#:
for (int i = 0; i < 3; i++)
{
Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedByRandom(MathHelper.ToRadians(12));
Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI);
}
return false;
What I've learned from this so far -
To begin with, the for loop is basically telling the game how many projectiles to spawn.
Projectile.NewProjectile is responsible for spawning a new projectile. The position.X and Y tell the projectile where to spawn. In this case, the center of the weapon - more specifically, the center of the weapon as you rotate the weapon around 360 degrees - has to do with vectors. The speed X and Y also have to do with vectors, and I'm seriously lacking knowledge on this subject (I do know it has to do with direction and magnitude). The type is just the type of projectile (in my case mod.ProjectileType<modProjectile>()). The damage here can be set independently of the weapon's damage (basically, it will ignore weapon damage and bonuses) - if I'm wrong about this, just let me know, but this is how it was explained to me. Knockback is self explanatory. The player.whoAmI (I believe) just sets who shot it?? (not sure on this one).
If I'm wrong about any of this, please feel free to correct me.
Obviously, these new projectiles will always originate from the center of the weapon, so that's not what we want.
I feel like this problem has to do with vectors, from what little I know of them, and from what I've seen in very basic YouTube video explanations on the subject.
Now, here's where I try to explain how stupid I am (this is more or less just thinking out loud) --
Alright, so let's say that when the weapon is rotated (which can rotate 360 degrees), it's sprite (or image) has to move around a center point (we'll call this X0 and Y0). Obviously, the weapon sprite doesn't rotate around it's own center, it has to be rotating around some other point (perhaps the player?). Therefore, the sprite of the weapon must be offset from that point by a certain amount. So, if it's offset from the player's center, this make perfect sense, and I believe this has to do with vectors.
So, if I drew a line from X0, Y0 to Y10 and placed a point at each spot, then rotated that line using X0, Y0 as an axis, rotating by 90 degrees would eventually get me a line from X0, Y0 to X10 (or -X10, depending on which way you rotated). OK, so with that in mind, I think of a weapon's rotation around the player's center the same way. Therefore, using the above example, shooting a projectile straight up in the air, the projectile would originate from Y10.
I should point out that I have no idea if projectiles in Terraria use the player as the rotation point for the firing of said projectiles. It would make sense, but from what I've seen in the code, it may have to do with the weapon, so maybe the player's center is just a reference for the weapon and it's firing center? Just curious.
If I want to offset a projectile's originating position, I can't just change the center of rotation, as the projectile's firing position would appear to change as the weapon was rotated around 360 degrees (this is why offsetting from position.X and position.Y in NewProjectile won't work). There must be a way to still use the player's center (or whatever the weapon is using as it's rotational axis), and then just rotate the line slightly using that axis, making the projectile appear to be originating from an offset of the weapon's firing center. Then, rotate the projectile itself by a small amount to account for the change (otherwise, it would still appear to be shooting at an angle from the weapon itself).
Alright, so now that I've completely embarrassed myself, I will defer to the more experienced users to lend me a helping hand on this one. If I'm even close, I'd be surprised, but logically speaking, my explanation does make sense, at least in my head. Again, I have no clue if Terraria handles projectiles this way, so please feel free to correct me.
I'm the type of person that has to know how things work, so I can't just ask for code and be on my way. I need to know how things are functioning
Last edited: