- 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
Follow this Question
Related Questions
Zero friction, zero drag, zero gravity bouncy ball in 2D 1 Answer
Maths with variables 2 Answers
Simple question about unity 5 rigidbody/gravity 1 Answer
How to make an arrow fly realistically. 3 Answers
What is the easiest way to increase horizontal speed with gravity to experience same jump distance 0 Answers