- Home /
Change Speed of Multiple Objects of the same Class
I'm working on a 2D game where there are multiple balls bouncing around the screen in 0 gravity. I want to be able to adjust their speed when a player clicks a powerup. I figured out that I can use Time.timescale() to adjust the overall game speed. However, since my powerups are on a spawn timer(in another class), will changing the ball speed using timescale impact the powerup timer? Also, the balls appear to move in a choppy manner when I slow things down too much using timescale.
TL:DR - How can I apply opposing force to all my 2D objects moving in multiple directions at once to slow them down? Or is there a better way to do it?
Answer by Jordash · Oct 24, 2018 at 01:13 AM
I would:
1) set up public methods in your ball class that achieves your slow down / speed up goals.
2) have a static game manager class which maintains a collection of some kind to which the balls are added on creation and removed on destruction
3) when the powerup is used call a method in the game manager to iterate through the ball collection and call the slow down method for each
Answer by SpringerCodes · Oct 24, 2018 at 06:29 PM
Thanks, I'll give that a go and see where it gets me. I'll share the code when finished.
Your answer
Follow this Question
Related Questions
Push multiple objects away from explosion [2D] 1 Answer
Horizontal attraction? 0 Answers
How to i add force in a angle i have got? 1 Answer
Random increase of int in PlayerPrefs 0 Answers
Creating 'redstone' like wires 1 Answer