Velocity of the ball different - way to control it

Quick question: You use Phisics 2D to change velocity of the ball but i did in in the different way:

this.rigidbody2D.velocity = new Vector2 (2f, 10f)*2;
i just multiply new Vector2 by 2 .
Is it ok to do that?? can I control speed of power-ups falling from destroyed bricks?

Regards
Simon

Hi @Simon_Ireland,

Is it ok to do that??

You could do it that way, as you said, it works. What you are effectively doing is scaling the vector. So, in the above example it would be the same as;

this.rigidbody2D.velocity = new Vector2 (4f, 20f);

Couple of things you may want to consider though. Without consider the duration between frames your movement might start to get a bit jittery, especially considering the larger steps that, in this example, have been applied.

Also, multiplying the vector by a hard coded value may not be so beneficial in the long term. It would be better to set a variable to a value, and then multiply by that variable etc.

Also, can I control speed of power-ups falling from destroyed bricks?

Yes. You could use physics and apply gravity to them, or, move them yourself through code.

Hope this helps.

WOW that was quick :slight_smile:
Thanks a lot yes that will help.

1 Like

You’re more than welcome Simon :slight_smile: