Table not incrementing values

Hi,

so I have a table to hold a set of angles.

I loop through the table and call the angles which are then applied to a *pre loaded array of bullets (* that works fine ).

I have used this method lots in the past for positioning all types of things without issue( maybe a bit rusty though :)) , the commented out math random line works as expected.

substituting this line:

 local dx, dy = math.cos(angle) \* speed, math.sin(angle) \* speed

with this:

 local dx, dy = math.cos(bulletAngles[i]) \* speed, math.sin(bulletAngles[i]) \* speed

dosnt work either…hmmm

Question: why is the table only applying the last angle to ALL the bullets?

thank you

local bulletAngles = { 130, 120, 110, 100, 90, 80, 70, 60, 50 } for i = 1, 9 do local angle = bulletAngles[i] --math.random(-math.pi, math.pi) local speed = 0.09 local dx, dy = math.cos(angle) \* speed, math.sin(angle) \* speed bullet:applyLinearImpulse(dx, dy, bullet.x, bullet.y) end

If you have 9 bullets you probably mean

bullet[i]:applyLinearImpulse(dx, dy, bullet[i].x, bullet[i].y)

OOps, obvious mistake.

Thanks

Also, are you sure your impulse magnitude is sufficient and correct.

For one thing, I can see you’re ignoring mass, so if you ever change the bullet sizes in the future, this code will stop working the way it is now.

You can account for mass as follows:

local mass = bullet[i].mass bullet[i]:applyLinearImpulse( dx \* mass, dy \* mass, bullet[i].x, bullet[i].y)

Now, once you’re happy with the speed of your current bullets, if you later decide to double the size of the bullets, your speed calculations won’t need to be adjusted.

@RoamimgGamer

I had nt considered the mass as of yet, I am just trying to lay down some rules regarding the bullets.

However, again, I would not have considered this so thank you .

I still have another issue but will explain in detail when I can spend more time with the post, I want to be exact so as not to waste anyones time and efforts.

If you have 9 bullets you probably mean

bullet[i]:applyLinearImpulse(dx, dy, bullet[i].x, bullet[i].y)

OOps, obvious mistake.

Thanks

Also, are you sure your impulse magnitude is sufficient and correct.

For one thing, I can see you’re ignoring mass, so if you ever change the bullet sizes in the future, this code will stop working the way it is now.

You can account for mass as follows:

local mass = bullet[i].mass bullet[i]:applyLinearImpulse( dx \* mass, dy \* mass, bullet[i].x, bullet[i].y)

Now, once you’re happy with the speed of your current bullets, if you later decide to double the size of the bullets, your speed calculations won’t need to be adjusted.

@RoamimgGamer

I had nt considered the mass as of yet, I am just trying to lay down some rules regarding the bullets.

However, again, I would not have considered this so thank you .

I still have another issue but will explain in detail when I can spend more time with the post, I want to be exact so as not to waste anyones time and efforts.