- Home /

# Calculate speed for distance with bpm

Ok, this must be a really *wierd* one, but the thing is: I'm making a pong-like game where BPM is essential because I want that every beat, the ball collide with the players' wall; **I already fixed any problem that can lead to the loss of rhythm** (such as position change or maintaining the speed of x constant), that is no problem, but the thing is, **how can I calculate the speed that I need for the ball to collide every beat, knowing how many bpm the song is?**

More than a Unity question, is more a math question...

If you need more info, just ask. Thanks!

**Answer** by BastianUrbach
·
Dec 01, 2019 at 08:49 AM

First, calculate the beats per second:

beatsPerSecond := beatsPerMinute / 60From that, calculate the time between two beats:

secondsPerBeat := 1 / beatsPerSecondFinally, calculate the velocity using the distance you need to cover within one beat:

velocity := distance / secondsPerBeat

In short:

velocity := distance * beatsPerMinute / 60

Now that's just the velocity you need if the ball was using the shortest path but it's actually travelling diagonally. Assuming your game is layed out from left to right like the original pong game, you can easily calculate the velocity

**vector**like this:

velocityVector := direction / direction.x * velocityThis makes sure that no matter the angle, the ball always travels at the given velocity along the x-axis.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Firing A Projectile Along A Parabola 1 Answer

how to check if a number is between one range 4 Answers

Maths with variables 2 Answers

Zero friction, zero drag, zero gravity bouncy ball in 2D 1 Answer

How to make an arrow fly realistically. 3 Answers