How to change values for certain instances and not all

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SpokenOne420

Ex:
I created a player where he instances a bullet and shoots it right if he is facing right. When he faces left, the speed of the Bullet is changed to negative to make it go left. However, when the value is changed, it affects all bullets previously shot and changes their directtion when I just want to change the direction of that one instance and to others based on the direction of the player.

Please help:)

:bust_in_silhouette: Reply From: zhyrin

Without more information it’s hard to pinpoint what causes this behaviour. How does a bullet store it’s speed and how does it use it? How is the bullet speed changed?
What comes to mind is that all of your bullet scenes share a speed value. If a shared value is updated, all scenes that use that value will act accordingly. You would want each bullet to have a unique speed value.
If it’s in a resource, usually there is an option to make a resource local to scene, that way each scene will have it’s own copy.

Consideration:
It doesn’t really make sense for something to have negative speed, right? If it needs to go the other way, you would want the direction to change, but have the same speed.
You could give each instanced bullet a direction that is based on where the player is supposed to shoot when you spawn the bullet, and the bullet applies speed based on it’s direction.