Hi.. I'm new here and

This is my first post. i don’t want to come in all needy asking for help (which I’ll be doing A LOT if i can’t figure it out or watch a tutorial)

I need help with my bullets. So far it goes:
Press E → create bullet at playerX.Player.Y.
Permanent force 300 X axis
Player flip → permanent force -300 X axis

Now… If my player is facing right it’s fine, but if I’m facing left, then the bullets i already shot come flying back in my direction. I want it so if i shot right, bullets will go right, if i shoot left, bullets will go left but it will not affect the old bullets i already shot.

I think I know how to fix it!

I’m assuming you’re using a variable to change the speed in the X Axis? So, when you flip the Player you set the value of the variable to -300 as opposed to 300?
I think the reason why it happens is because the action KEEPS ON PLAYING after you create the bullet, always adding more speed to the bullets every frame. So, if you create a bullet, its permanent speed keeps being increased by +300 every frame - and when you change the value of the force, it starts to add -300 to the force, which is the same as subtracting 300 - and it results in the Bullet changing its direction.

A way to fix that would be to through a CONDITION, though! And I know just what to do!
When you add the force, use the condition “If object is stopped” - to make sure the force will ONLY BE ADDED to the bullets that AREN’T moving already! Something like this:

For each Bullet object
If Bullet is stopped
  add to Bullet a permanent force of Variable(Force) p/s on X axis and 0 p/s on Y axis

If Player is horizontally flipped (Inverted Condition)
  do = 300 to scene variable "Force"

If Player is horizontally flipped
  do = -300 to scene variable "Force"

This will make sure not only that the Bullets won’t turn the other way when you add the force, but also that the bullets will not GET FASTER as time goes!

I hope this helps! ^^

Also, a personal suggestion:
Instead of using the regular “Add a force” action and changing the X Axis values, why not use the “Add a force (Angle)” action and change the Angle of the bullets without needing to change their speed?
If the player is facing Right, the Angle could be “0”, shooting straight to the right.
If the player is facing Left, the Angle could be “180”, shooting straight to the left.
It’s up to you, though! I just find it to be a bit easier to work with than using a negative speed!

Aaaand now that this is out of the way… Hi welcome to the forum!
Also, don’t be afraid to ask for help. ^^ This is what this part of the forum is for, after all! And if you ever feel too nervous to make a thread, feel free to just PM me. I’m always happy to help!

1 Like

thanks for all your help. when i used to download other peoples code and assets and stick em in my game in unity, i didn’t understand most of that javascript either. haha. like i used to just copy what the tutorial guy does.

1 Like